forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request swiftlang#30101 from hborla/dynamic-replacement-ty…
…pe-erasure [Sema] Implement type erasure for dynamic replacement.
- Loading branch information
Showing
11 changed files
with
213 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// RUN: %target-swift-frontend -typecheck -disable-availability-checking -dump-ast %s | %FileCheck %s | ||
|
||
class AnyP: P { | ||
init<T: P>(erasing: T) {} | ||
} | ||
|
||
@_typeEraser(AnyP) | ||
protocol P {} | ||
|
||
struct ConcreteP: P, Hashable {} | ||
|
||
// CHECK-LABEL: testBasic | ||
dynamic func testBasic() -> some P { | ||
// CHECK: underlying_to_opaque_expr{{.*}}'some P' | ||
// CHECK-NEXT: call_expr implicit type='AnyP'{{.*}}arg_labels=erasing: | ||
// CHECK: call_expr type='ConcreteP' | ||
ConcreteP() | ||
} | ||
|
||
// CHECK-LABEL: testTypeAlias | ||
typealias AliasForP = P | ||
dynamic func testTypeAlias() -> some AliasForP { | ||
// CHECK: underlying_to_opaque_expr{{.*}}'some P' | ||
// CHECK-NEXT: call_expr implicit type='AnyP'{{.*}}arg_labels=erasing: | ||
// CHECK: call_expr type='ConcreteP' | ||
ConcreteP() | ||
} | ||
|
||
// CHECK-LABEL: testNoDynamic | ||
func testNoDynamic() -> some P { | ||
// CHECK: underlying_to_opaque_expr{{.*}}'some P' | ||
// CHECK-NEXT: call_expr type='ConcreteP' | ||
ConcreteP() | ||
} | ||
|
||
// CHECK-LABEL: testNoOpaque | ||
dynamic func testNoOpaque() -> P { | ||
// CHECK: erasure_expr implicit type='P' | ||
// CHECK-NEXT: normal_conformance type=ConcreteP protocol=P | ||
// CHECK-NEXT: call_expr type='ConcreteP' | ||
ConcreteP() | ||
} | ||
|
||
// CHECK-LABEL: testComposition | ||
typealias Composition = P & Hashable | ||
dynamic func testComposition() -> some Composition { | ||
// CHECK: underlying_to_opaque_expr{{.*}}'some Hashable & P' | ||
// CHECK-NEXT: call_expr type='ConcreteP' | ||
ConcreteP() | ||
} | ||
|
||
// CHECK-LABEL: struct_decl{{.*}}Builder | ||
@_functionBuilder | ||
struct Builder { | ||
static func buildBlock(_ params: P...) -> ConcreteP { | ||
return ConcreteP() | ||
} | ||
} | ||
|
||
// CHECK-LABEL: TestFunctionBuilder | ||
class TestFunctionBuilder { | ||
// CHECK-LABEL: testTransformFnBody | ||
@Builder dynamic var testTransformFnBody: some P { | ||
// CHECK: return_stmt | ||
// CHECK-NEXT: underlying_to_opaque_expr implicit type='some P' | ||
// CHECK-NEXT: call_expr implicit type='AnyP'{{.*}}arg_labels=erasing: | ||
// CHECK: declref_expr implicit type='@lvalue ConcreteP' | ||
ConcreteP() | ||
} | ||
|
||
// CHECK-LABEL: func_decl{{.*}}takesBuilder | ||
func takesBuilder(@Builder closure: () -> ConcreteP) -> ConcreteP { closure() } | ||
|
||
// CHECK-LABEL: testClosureBuilder | ||
dynamic var testClosureBuilder: some P { | ||
// CHECK: underlying_to_opaque_expr implicit type='some P' | ||
// CHECK-NEXT: call_expr implicit type='AnyP'{{.*}}arg_labels=erasing: | ||
// CHECK: closure_expr type='() -> ConcreteP' | ||
takesBuilder { | ||
// CHECK: return_stmt | ||
// CHECK-NEXT: load_expr implicit type='ConcreteP' | ||
ConcreteP() | ||
} | ||
} | ||
} | ||
|
||
// CHECK-LABEL: class_decl{{.*}}DynamicReplacement | ||
class DynamicReplacement { | ||
dynamic func testDynamicReplaceable() -> some P { | ||
// CHECK: underlying_to_opaque_expr implicit type='some P' | ||
// CHECK-NEXT: call_expr implicit type='AnyP'{{.*}}arg_labels=erasing: | ||
// CHECK: call_expr type='ConcreteP' | ||
ConcreteP() | ||
} | ||
} | ||
|
||
// CHECK-LABEL: extension_decl{{.*}}DynamicReplacement | ||
extension DynamicReplacement { | ||
// CHECK-LABEL: testDynamicReplacement | ||
@_dynamicReplacement(for: testDynamicReplaceable) | ||
func testDynamicReplacement() -> some P { | ||
print("not single expr return") | ||
// CHECK: return_stmt | ||
// CHECK-NEXT: underlying_to_opaque_expr implicit type='some P' | ||
// CHECK-NEXT: call_expr implicit type='AnyP'{{.*}}arg_labels=erasing: | ||
// CHECK: call_expr type='ConcreteP' | ||
return ConcreteP() | ||
} | ||
} |
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