-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SE-0280] Enum cases as protocol witnesses #28916
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6022ea0
[Typechecker] Allow enum cases without payload to witness a static ge…
theblixguy 6c4a727
[SIL] Add support for payload cases as well
theblixguy 0626eef
[SILGen] Clean up comment
theblixguy 914e1dc
[Typechecker] Re-enable some previously disabled witness matching code
theblixguy 7d53900
[Test] Update typechecker tests with payload enum test cases
theblixguy 7a1d402
[Test] Update SILGen test
theblixguy 8748608
[SIL] Add two FIXME's to address soon
theblixguy 7d3cf17
[SIL] Emit the enum case constructor unconditionally when an enum cas…
theblixguy 7385ad1
[SILGen] Properly handle a enum witness in addMethodImplementation
theblixguy c623f8f
[TBDGen] Handle enum case witness
theblixguy e9357d4
[Typechecker] Fix conflicts
theblixguy 015df5f
[Test] Fix tests
theblixguy af9b7ce
[AST] Fix indentation in diagnostics def file
theblixguy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// RUN: %target-swift-emit-silgen %s | %FileCheck %s | ||
|
||
protocol Foo { | ||
static var button: Self { get } | ||
} | ||
|
||
enum Bar: Foo { | ||
case button | ||
} | ||
|
||
protocol AnotherFoo { | ||
static func bar(arg: Int) -> Self | ||
} | ||
|
||
enum AnotherBar: AnotherFoo { | ||
case bar(arg: Int) | ||
} | ||
|
||
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s21protocol_enum_witness3BarOAA3FooA2aDP6buttonxvgZTW : $@convention(witness_method: Foo) (@thick Bar.Type) -> @out Bar { | ||
// CHECK: bb0([[BAR:%.*]] : $*Bar, [[BAR_TYPE:%.*]] : $@thick Bar.Type): | ||
// CHECK-NEXT: [[META_TYPE:%.*]] = metatype $@thin Bar.Type | ||
// CHECK: [[REF:%.*]] = function_ref @$s21protocol_enum_witness3BarO6buttonyA2CmF : $@convention(method) (@thin Bar.Type) -> Bar | ||
// CHECK-NEXT: [[RESULT:%.*]] = apply [[REF]]([[META_TYPE]]) : $@convention(method) (@thin Bar.Type) -> Bar | ||
// CHECK-NEXT: store [[RESULT]] to [trivial] [[BAR]] : $*Bar | ||
// CHECK-NEXT: [[TUPLE:%.*]] = tuple () | ||
// CHECK-NEXT: return [[TUPLE]] : $() | ||
// CHECK-END: } | ||
|
||
// CHECK-LABEL: sil hidden [transparent] [ossa] @$s21protocol_enum_witness3BarO6buttonyA2CmF : $@convention(method) (@thin Bar.Type) -> Bar { | ||
// CHECK: bb0({{%.*}} : $@thin Bar.Type): | ||
// CHECK-NEXT: [[CASE:%.*]] = enum $Bar, #Bar.button!enumelt | ||
// CHECK-NEXT: return [[CASE]] : $Bar | ||
// CHECK-END: } | ||
|
||
// CHECK-LABEL: sil private [transparent] [thunk] [ossa] @$s21protocol_enum_witness10AnotherBarOAA0D3FooA2aDP3bar3argxSi_tFZTW : $@convention(witness_method: AnotherFoo) (Int, @thick AnotherBar.Type) -> @out AnotherBar { | ||
// CHECK: bb0([[ANOTHER_BAR:%.*]] : $*AnotherBar, [[INT_ARG:%.*]] : $Int, [[ANOTHER_BAR_TYPE:%.*]] : $@thick AnotherBar.Type): | ||
// CHECK-NEXT: [[META_TYPE:%.*]] = metatype $@thin AnotherBar.Type | ||
// CHECK: [[REF:%.*]] = function_ref @$s21protocol_enum_witness10AnotherBarO3baryACSi_tcACmF : $@convention(method) (Int, @thin AnotherBar.Type) -> AnotherBar | ||
// CHECK-NEXT: [[RESULT:%.*]] = apply [[REF]]([[INT_ARG]], [[META_TYPE]]) : $@convention(method) (Int, @thin AnotherBar.Type) -> AnotherBar | ||
// CHECK-NEXT: store [[RESULT]] to [trivial] [[ANOTHER_BAR]] : $*AnotherBar | ||
// CHECK-NEXT: [[TUPLE:%.*]] = tuple () | ||
// CHECK-NEXT: return [[TUPLE]] : $() | ||
// CHECK-END: } | ||
|
||
// CHECK-LABEL: sil_witness_table hidden Bar: Foo module protocol_enum_witness { | ||
// CHECK: method #Foo.button!getter: <Self where Self : Foo> (Self.Type) -> () -> Self : @$s21protocol_enum_witness3BarOAA3FooA2aDP6buttonxvgZTW | ||
|
||
// CHECK-LABEL: sil_witness_table hidden AnotherBar: AnotherFoo module protocol_enum_witness { | ||
// CHECK: method #AnotherFoo.bar: <Self where Self : AnotherFoo> (Self.Type) -> (Int) -> Self : @$s21protocol_enum_witness10AnotherBarOAA0D3FooA2aDP3bar3argxSi_tFZTW |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In practice, enum constructors never have public linkage so they don't need to be visited by TBDGen. However in case this ever changes, there's one less spot to update...