Commit Graph

803 Commits

Author SHA1 Message Date
Doug Gregor
e260d65f71 Add @safe(unchecked) to allow unsafe code within a declaration.
Introduce an attribute to allow unsafe code within the annotated
declaration without presenting an unsafe interface to users. This is,
by its nature, and unsafe construct, and is used to document where
unsafe behavior is encapsulated in safe constructs.

There is an optional message that can be used as part of an audit
trail.
2024-12-13 11:36:40 -08:00
Rintaro Ishizaki
21c9d3adcb [ASTGen] Use arch(_:) instead of _pointerBitWidth(_:)
We still need to support older Swift compilers which does't have
'_pointerBitWidth(_:)' pletform condition.
2024-12-12 10:54:53 -08:00
Rintaro Ishizaki
71ca3e129a [ASTGen] Use syntax tree based interface hash 2024-12-12 09:51:09 -08:00
Rintaro Ishizaki
54225961e3 [ASTGen] Add syntax tree based Fingerprint 2024-12-12 09:51:09 -08:00
Joe Groff
8436db3b9d Merge pull request #78021 from jckarter/addressable-params-2
Add an `@_addressableSelf` attribute to mark the self param of methods as addressable.
2024-12-09 08:42:49 -08:00
Rintaro Ishizaki
7fd97c974c [ASTGen] Factor out attribute list handling logic 2024-12-07 07:39:10 -08:00
Rintaro Ishizaki
55f61d0781 [ASTGen] Handle multiple attributes
`@available` and some attributes emits multiple AST attributes from a
single syntactic attribute. Prepare for them.
2024-12-07 07:39:10 -08:00
Doug Gregor
e210b103fe Remove unused variable to suppress warning 2024-12-06 23:07:12 -08:00
Doug Gregor
02a20ded57 [Parsers] Stop sharing CustomAttributeInitializer instances across properties
We don't need to share them, and it's far simpler if we don't.
2024-12-06 17:40:34 -08:00
Doug Gregor
ee9c066050 Introduce a new Initializer subclass for the arguments of custom attributes
Since the introduction of custom attributes (as part of property
wrappers), we've modeled the context of expressions within these
attributes as PatternBindingInitializers. These
PatternBindingInitializers would get wired in to the variable
declarations they apply to, establishing the appropriate declaration
context hierarchy. This worked because property wrappers only every
applied to---you guessed it!---properties, so the
PatternBindingInitializer would always get filled in.

When custom attributes were extended to apply to anything for the
purposes of macros, the use of PatternBindingInitializer became less
appropriate. Specifically, the binding declaration would never get
filled in (it's always NULL), so any place in the compiler that
accesses the binding might have to deal with it being NULL, which is a
new requirement. Few did, crashes ensued.

Rather than continue to play whack-a-mole with the abused
PatternBindingInitializer, introduce a new CustomAttributeInitializer
to model the context of custom attribute arguments. When the
attributes are assigned to a declaration that has a
PatternBindingInitializer, we reparent this new initializer to the
PatternBindingInitializer. This helps separate out the logic for
custom attributes vs. actual initializers.

Fixes https://github.com/swiftlang/swift/issues/76409 / rdar://136997841
2024-12-06 17:40:32 -08:00
Joe Groff
ac7a61679d Add an @_addressableSelf attribute to mark the self param of methods as addressable. 2024-12-06 16:54:01 -08:00
Rintaro Ishizaki
985edf5916 Merge pull request #77905 from rintaro/astgen-declattr-pt2
[ASTGen] Generate several attributes
2024-12-06 09:24:07 -08:00
Rintaro Ishizaki
6d7b3d69d1 [ASTGen] Generate several attributes
* NonisolatedAttr
* SpecializeAttr
* UnavailableFromAsyncAttr
* DocumentationAttr
* StorageRestrictionsAttr
2024-12-05 15:12:00 -08:00
Joe Groff
a045d665bb Merge pull request #75282 from jckarter/addressable-params-1
[WIP] Prototype an `@_addressable` attribute that puts an argument at a stable address.
2024-12-05 09:17:26 -08:00
Rintaro Ishizaki
507e81633e [ASTDumper] Dump decl attributes
Previously only some random decl attributes were included in the dump
with the source spelling (e.g. @objc), or some affected how the decl is
dumped. But the full attribute list has not been dumped. Dumping
attributes are useful for debugging attribute handling.
2024-12-03 21:27:24 -08:00
Joe Groff
3c0b08dbcb Prototype an @_addressable attribute that puts an argument at a stable address.
Many APIs using nonescapable types would like to vend interior pointers to their
parameter bindings, but this isn't normally always possible because of representation
changes the caller may do around the call, such as moving the value in or out of memory,
bridging or reabstracting it, etc. `@_addressable` forces the corresponding parameter
to be passed indirectly in memory, in its maximally-abstracted representation.
[TODO] If return values have a lifetime dependency on this parameter, the caller must
keep this in-memory representation alive for the duration of the dependent value's
lifetime.
2024-12-03 20:39:23 -08:00
Jakub Florek
866f1c1c04 Merge branch 'main' into swift-lexical-lookup-validation 2024-11-26 09:37:23 +01:00
Jakub Florek
0371783aca Merge branch 'swift-lexical-lookup-validation' of https://github.com/MAJKFL/swift into swift-lexical-lookup-validation 2024-11-26 09:34:39 +01:00
Jakub Florek
024f6304b0 Add a basic SwiftLexicalLookup validation test. Add caching of ConfiguredRegions to unqualified lookup validation. 2024-11-26 09:34:33 +01:00
Rintaro Ishizaki
392185e0d7 Merge pull request #77721 from rintaro/astgen-virtualfiles
[ASTGen] Handle '#sourceLocation' directives
2024-11-21 12:35:03 -08:00
Rintaro Ishizaki
e153164677 [ASTGen] Handle '#sourceLocation' directives
Use `ExportedSourceFile.sourceLocationConverter.lineTable.virtualFiles`
to populate the information in `swift::SourceManger` and
`swift::SourceFile` when "parsing" with ASTGen
2024-11-21 08:23:08 -08:00
Rintaro Ishizaki
40c8d817fb [Diagnostics] Support "swift" style diagnostics at EOF
Adjust the valid position checking and special handle EOF position.
If the requested location is at EOF, use the last token, but still
emit the diagnostics at the specificied location.

rdar://138426038
2024-11-21 06:27:37 -08:00
Rintaro Ishizaki
45cd42fc4e Merge pull request #77735 from rintaro/astgen-declattr-simples
[ASTGen] Generate some SIMPLE attributes
2024-11-20 13:33:58 -08:00
Rintaro Ishizaki
256609fb47 [ASTGen] Generate some SIMPLE attributes 2024-11-20 09:21:32 -08:00
Doug Gregor
c5de02f60e Merge pull request #77628 from DougGregor/clang-importer-parse-request
[Clang importer] Use ParseSourceFileRequest for parsing swift_attr attributes
2024-11-16 01:12:27 -08:00
Rintaro Ishizaki
5e6904f8c7 [ASTGen] Add a convenient method to process attribute arguments 2024-11-15 15:45:16 -08:00
Jakub Florek
5b39ba66b8 Merge branch 'main' into swift-lexical-lookup-validation 2024-11-15 22:05:43 +01:00
Doug Gregor
7872fc6c4b Introduce DeclAttribute::clone() to clone declaration attributes (obviously) 2024-11-15 09:02:45 -08:00
Rintaro Ishizaki
1fc00ae248 [ASTGen] Remove LegacyParser ping-pong mechanism
Now that ASTGen should be able to generate most Swift code. Let's
remove "legacy parser" call-in, and remove the unhealthy cyclic
dependency between lib/Parse and ASTGen.
2024-11-14 22:46:43 -08:00
Rintaro Ishizaki
f47c2b353f [ASTGen] Generate CustomAttr
Update macro tests
2024-11-14 15:10:12 -08:00
Rintaro Ishizaki
0f1b650716 [AST] MacroRoleAttr accept any 'Expr *' as the conformances arguments 2024-11-14 15:10:11 -08:00
Rintaro Ishizaki
093d0dffb4 [ASTGen] Generate MacroDecl 2024-11-14 15:10:08 -08:00
Rintaro Ishizaki
97eda9ac03 Merge pull request #77608 from rintaro/astgen-decl-optional
[ASTGen] Skip named decls with missing name
2024-11-14 09:45:44 -08:00
Jakub Florek
d724230a91 Add casting of exported source file syntax to SourceFileSyntax. 2024-11-14 13:22:27 +01:00
Jakub Florek
34c90f1c01 Merge remote-tracking branch 'upstream/main' into swift-lexical-lookup-validation 2024-11-14 10:38:20 +01:00
Rintaro Ishizaki
c4955edb6d [ASTGen] Skip value decls missing the name 2024-11-13 23:09:03 -08:00
Rintaro Ishizaki
2891d9e460 [ASTGen] Make generate(decl:) return optional value 2024-11-13 23:01:40 -08:00
Doug Gregor
8f5e941667 [ASTGen] Move unimplemented macro role case down 2024-11-13 21:22:02 -08:00
Doug Gregor
989c73d014 Ensure that buffers containing Clang swift_attr attributes are parsed as attributes
Previously, they were being parsed as top-level code, which would cause
errors because there are no definitions. Introduce a new
GeneratedSourceInfo kind to mark the purpose of these buffers so the
parser can handle them appropriately.
2024-11-13 21:19:37 -08:00
Rintaro Ishizaki
ac8dd89ffd [ASTGen] Generate 'switch' expressions 2024-11-13 10:25:50 -08:00
Jakub Florek
3ef2312a3e Merge branch 'swift-lexical-lookup-validation' of https://github.com/MAJKFL/swift into swift-lexical-lookup-validation 2024-11-13 17:43:46 +01:00
Jakub Florek
8fc6951c9f Use ConfiguredRegions instead of BuildConfiguration with LookupConfig. 2024-11-13 17:43:12 +01:00
Jakub Florek
4b544e963a Merge branch 'main' into swift-lexical-lookup-validation 2024-11-13 15:54:30 +01:00
Rintaro Ishizaki
0ba92d84e5 [ASTGen] Generate closure signatures
Still TODO:
* Capture list
* Anonymous parameters
2024-11-11 12:21:38 -08:00
Alejandro Alonso
13406e3b58 Update Exprs.swift 2024-11-06 13:56:09 -08:00
Alejandro Alonso
5520baeab0 Address ASTGen feedback 2024-11-06 13:55:01 -08:00
Alejandro Alonso
ba3bc1d5f1 Implement ASTGen changes for integer generics from Swift Syntax
Support negatives
2024-11-06 13:54:59 -08:00
Rintaro Ishizaki
bba4f65b6c Merge pull request #77404 from rintaro/astgen-diagnostics-simple
[ASTGen] Simplify diagnostics framework
2024-11-06 10:59:36 -08:00
Rintaro Ishizaki
47f27a411c Merge pull request #77398 from rintaro/astgen-keypathexpr
[ASTGen] Generate Swift key-path expressions
2024-11-06 10:15:37 -08:00
Rintaro Ishizaki
dc156a644a [ASTGen] Generate Swift key-path expressions 2024-11-05 13:38:21 -08:00