-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Implement Value generics #75518
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
Implement Value generics #75518
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
75c2cbf
Implement value generics
Azoy 3e9c463
Add some new diagnostics and tests
Azoy 7c85261
Add runtime support
Azoy 71f1bb3
Fix compile error in TypeRefBuilder
Azoy a029900
Update raw_layout.swift
Azoy 8b773dc
Add an ArrayLayoutEntry and dispatch to that for array raw layout
Azoy b663a15
Add tests for raw layout vector
Azoy f66beff
Fix unittest compile error
Azoy 7eb93b8
Update SpecifierDSL.h
Azoy 0df42e9
Lower UDRE to TypeValue if it references a value generic
Azoy f4f60f4
Remove Value requirement Add GenericTypeParamKind
Azoy a434126
Disallow referencing a value generic outside of certain contexts
Azoy 1ff1b94
AST: Pick off some usages of GenericTypeParamType::getDecl()
slavapestov b9b6bb7
AST: Introduce new kind of sugared GenericTypeParamType
slavapestov 71fee06
Requestify GTPD::getValueType
Azoy 7cd4248
Move some value checking to desugaring
Azoy 4f07c06
Future proof the initRawStructMetadata entrypoint
Azoy e0f2b81
Add serialization and parser tests for SIL
Azoy 19fc174
Don't create fake GTPDs for SIL generic signatures
Azoy bfffd7e
Set the param kind in ASTGen
Azoy 15db739
Serialize IntegerType
Azoy b35ac50
Optimize TypeValueInst in Swift
Azoy f25545b
Add a module interface test
Azoy bd18bb3
Update ASTDumperTests.cpp
Azoy 4a7fb6f
Some test fixes
Azoy 46a4d56
Bring back the isOpaqueType parameter for deserialization
Azoy 96bfaaf
Update ASTDumperTests.cpp
Azoy 22349bc
Use intptr_t instead of ssize_t and more test fixes
Azoy 9903d71
More changes to get off of ssize_t
Azoy 451e725
Add ValueGenerics experimental feature
Azoy c1dd957
Use intptr_t more consistently
Azoy 8a9303b
Consistently negate the value from demangling
Azoy 9906db3
Fix closures capturing value generics
Azoy 128a30c
Handle integer types in TypeTransform
Azoy 9faf615
Add runtime availability checking for value generics
Azoy f2f82a7
Add initRawStructMetadata2 for safety
Azoy 2c703ee
Update raw_layout.swift
Azoy 3d8a9d4
Implement same type checking at runtime
Azoy f431e00
Fix abi test for new initRaw runtime function
Azoy 17eb973
Update Devirtualize.cpp
Azoy 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
32 changes: 32 additions & 0 deletions
32
SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyMisc.swift
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,32 @@ | ||
//===--- SimplifyMisc.swift -----------------------------------------------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import SIL | ||
|
||
extension TypeValueInst: OnoneSimplifyable, SILCombineSimplifyable { | ||
func simplify(_ context: SimplifyContext) { | ||
// If our parameter is not known statically, then bail. | ||
guard paramType.isInteger() else { | ||
return | ||
} | ||
|
||
// Note: Right now, value generics only support 'Int'. If we ever expand the | ||
// scope of types supported, then this should change. | ||
let fieldType = type.getNominalFields(in: parentFunction)![0] | ||
|
||
let builder = Builder(before: self, context) | ||
let intLiteral = builder.createIntegerLiteral(value, type: fieldType) | ||
let structInst = builder.createStruct(type: type, elements: [intLiteral]) | ||
uses.replaceAll(with: structInst, context) | ||
context.erase(instruction: self) | ||
} | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.