-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow user-defined stack types that aren't value types #783
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yorickpeterse
added
feature
New things to add to Inko, such as a new standard library module
performance
Changes related to improving performance
compiler
Changes related to the compiler
labels
Dec 3, 2024
yorickpeterse
force-pushed
the
stack-types
branch
5 times, most recently
from
December 6, 2024 22:14
d5a99e0
to
d3cff96
Compare
This comment was marked as resolved.
This comment was marked as resolved.
yorickpeterse
force-pushed
the
stack-types
branch
3 times, most recently
from
December 7, 2024 23:31
9ecc573
to
6db033d
Compare
This comment was marked as resolved.
This comment was marked as resolved.
yorickpeterse
force-pushed
the
stack-types
branch
2 times, most recently
from
December 8, 2024 22:37
4da407c
to
a08ee42
Compare
This comment was marked as resolved.
This comment was marked as resolved.
yorickpeterse
force-pushed
the
stack-types
branch
2 times, most recently
from
December 9, 2024 23:27
3878e72
to
382f82d
Compare
yorickpeterse
force-pushed
the
stack-types
branch
3 times, most recently
from
December 10, 2024 19:42
7f2dd93
to
66dc241
Compare
This was referenced Dec 10, 2024
yorickpeterse
force-pushed
the
stack-types
branch
from
December 10, 2024 22:38
66dc241
to
fe867a6
Compare
This comment was marked as resolved.
This comment was marked as resolved.
yorickpeterse
force-pushed
the
stack-types
branch
from
December 10, 2024 23:49
fe867a6
to
8549788
Compare
This comment was marked as resolved.
This comment was marked as resolved.
yorickpeterse
force-pushed
the
stack-types
branch
4 times, most recently
from
December 13, 2024 21:44
1601664
to
b43ef93
Compare
This comment was marked as outdated.
This comment was marked as outdated.
yorickpeterse
force-pushed
the
stack-types
branch
from
December 14, 2024 23:46
2f59b9d
to
e2a2513
Compare
This comment was marked as resolved.
This comment was marked as resolved.
yorickpeterse
force-pushed
the
stack-types
branch
from
December 16, 2024 19:50
4c4a752
to
eb5aa81
Compare
This was referenced Dec 16, 2024
yorickpeterse
force-pushed
the
stack-types
branch
2 times, most recently
from
December 17, 2024 02:26
552c138
to
f6a7b90
Compare
Commit 8ca46bf introduces the ability to define stack allocated value types. This commit extends support to also allow defining of stack allocated types containing heap types. This means there are now three different kinds of allocation strategies: - class A: heap allocated, subject to single ownership - class inline A: stack allocated, subject to single ownership - class copy A: stack allocated, immutable value type that's copied upon a move When borrowing an `inline` type, the compiler copies the stack allocated portion and increments the borrow count for any heap values stored within. When dropping this copy, the borrow count is reduces. This means that borrowing an `inline` type is equivalent to borrowing all interior heap values, just without the need for doing so manually. This approach is inspired by Swift, which takes a similar approach using (atomic) reference counting. This fixes #780. Changelog: added
This adds the InvalidFileDescriptor constructor to the std.io.Error type, which is mapped to the EBADF error code. Changelog: added
For types such as tuples, Option, Result, and various others, there's no need to allocate them on the heap. In fact, for frequently used types such as Option and Result this does nothing but harm performance. To resolve this, various types are marked as `inline` such that they are allocated on the stack. IO types such as ReadOnlyFile and Stdout remain heap types for the time being, as this allows casting them to e.g. the Write trait. This in turn is useful if some deeply nested type needs to act on different Write types, but you don't want to litter generic type arguments all over the place. Changelog: performance
yorickpeterse
force-pushed
the
stack-types
branch
from
December 17, 2024 02:32
f6a7b90
to
52e4318
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
compiler
Changes related to the compiler
feature
New things to add to Inko, such as a new standard library module
performance
Changes related to improving performance
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Commit 8ca46bf adds support for defining stack allocated value types using the syntax
class inline Name { ... }
. Using that syntax, the types are restricted to storing otherinline
types such asInt
or a user-definedinline
type.This PR extends this setup to allow for stack types that can store heap types. The result is the following:
class A
defines a heap allocated type subject to single ownershipclass inline A
defines a stack allocated type subject to single ownershipclass copy A
defines a stack allocated, immutable value type that is copied upon a move (i.e. the oldclass inline A
setup)Relevant issues
TODO
inline
keyword with thecopy
keywordinline_*
diagnostics tests tocopy_*
inline
types are subject to move and not copy semanticsinline
andcopy
typesinline
types but notcopy
typesinline enum
supportinline
forOption
results in a shape missing compiler panicinline
orcopy
types (e.g.Option[Option[Int]]
)copy
type, we seem to trigger an LLVM SEGV, probably due to the size not being correctOption[A]
andOption[B]
) result in the same final symbol names, suggesting we're perhaps not taking into account shapes of sub types?ClassInstance
types, seemingly resulting in the wrong methods being used for callsinline
andcopy
types with a size of zero (= no fields)$increment
method forinline
types, and call this when borrowing aninline
type$increment
on anyinline
types stored inself
, and for heap types directly increments the borrow countinline
method$decrement
method forinline
types, and call this when dropping a borrow of aninline
type$decrement
on anyinline
types stored inself
, and for heap types directly decrements the borrow countinline
methodGenerateDropper
andGenerateInlineMethods
inline
types at the MIR levelStackRef
andStackMut
for borrows ofinline
typesfn mut
methods forinline
types, as heap values can still be mutated in place as expectedref T
andmut T
intoT
forinline
types, only do that forcopy
typesStackRef
andStackMut
shapes such that they call$increment
/$decrement
inko fmt
testsResult
aninline
type results in a segfault when running the standard library testsstd.sys.Stdout
aninline
type crashes thestd.sys
testsstd.stdio.Stdout
aninline
type crashes the test suiteinline
where appropriate, commit this separately from the main set of changesAfter the necessary code changes are made:
copy
keyword: inko-lang/tree-sitter-inko@1419efbcopy
keywordcopy
keyword