Commit Graph

29 Commits

Author SHA1 Message Date
Kuba (Brecka) Mracek
75506a17ce Merge pull request #85413 from kubamracek/section-convention-c
Allow function conversions to `@convention(c)` in `@section` expressions
2025-11-11 04:18:30 -08:00
Kuba Mracek
4e919fb235 Allow function conversions to @convention(c) in @section expressions 2025-11-10 09:34:38 -08:00
Kuba Mracek
ac49d93e3f Support 'as UInt8' in @section expressions 2025-11-10 09:02:40 -08:00
Kuba (Brecka) Mracek
f04efab969 Fix typo in SectionTopLevel.swift 2025-11-07 12:48:04 -08:00
Kuba (Brecka) Mracek
09146b1714 Relax expectations in SectionTopLevel.swift for 32-bit and arm64e 2025-11-07 10:48:50 -08:00
Kuba (Brecka) Mracek
b6c29f1ce6 Merge pull request #85136 from kubamracek/section-top-level
SE-0492: Handle top-level `@section`-annotated globals
2025-11-04 11:15:50 -08:00
Kuba (Brecka) Mracek
eaa3f8a5b0 Annotate SectionTopLevel.swift with REQUIRES: swift_feature_ParserASTGen 2025-11-03 21:11:05 -08:00
Kuba Mracek
ee623f8d59 Add @section/@const handling of globals to ASTGen too 2025-11-03 13:47:51 -08:00
Kuba Mracek
4544536065 Relax expectations in ConstValues/SectionIR.swift to allow for padding on 32-bit platforms 2025-10-27 11:33:15 -07:00
Kuba Mracek
ecdcb1be31 Make ConstValues/SectionIR.swift test compatible with 32-bit platforms 2025-10-26 09:59:59 -07:00
Kuba Mracek
05ca83b532 Adjust expectations in ConstValues/SectionIR.swift for arm64e 2025-10-25 12:41:46 -07:00
Kuba Mracek
5f81c1b793 SE-0492: Handle top-level @section-annotated globals
Currently, normal globals are represented as a PatternBindingDecl and a VarDecl in the AST, directly under the SourceFile:

```
// var variable_name = 42, compiled with -parse-as-library
(source_file ...
  (pattern_binding_decl ...
    (pattern_entry ...
      (pattern_named ... "variable_name") ...
  (var_decl "variable_name" ...
```

Top-level globals are represented more like local variables, under a TopLevelCodeDecl. Note that the VarDecl is still at the file scope. In SILGen, this case has some special handling to use the a storage of a global variable, and to avoid cleanups (see `emitInitializationForVarDecl`). Effectively, this means the globals are initialized inside the `main` function.

```
// var variable_name = 42, compiled without -parse-as-library
(source_file ...
  (top_level_code_decl ...
    (brace_stmt ...
      (pattern_binding_decl ...
        (pattern_named ... "variable_name") ...
  (var_decl "variable_name" ... top_level_global
```

SE-0492 needs top-level globals that have a `@section` annotation to behave like a normal global -- initialization must happen statically, and not in `main`. This PR changes the parsing of those globals to match normal globals, without the TopLevelCodeDecl wrapper. SILGen and IRGen then handles them correctly.
2025-10-25 10:48:44 -07:00
Kuba Mracek
ca737d3d97 Tweak diagnostic text on @section/@const errors 2025-10-23 17:05:41 -07:00
Kuba Mracek
f41ce336cf Drop unused MemberRefExpr handling in LegalConstExprVerifier, adjust tests 2025-10-23 17:02:15 -07:00
Kuba Mracek
19f3320f20 Better handling of metatypes and operators in LegalConstExprVerifier.cpp 2025-10-23 09:27:01 -07:00
Kuba Mracek
00fc1fad96 Add an XFAIL-ing test for top-level mode @section globals 2025-10-23 08:37:39 -07:00
Kuba Mracek
9d145bc277 Add an IR test for @section, check that we're producing constants 2025-10-23 08:27:15 -07:00
Kuba Mracek
adeb40f261 SE-0492: Stabilize @_section/@_used into @section/@used
Removes the underscored prefixes from the @_section and @_used attributes, making them public as @section and @used respectively. The SymbolLinkageMarkers experimental feature has been removed as these attributes are now part of the standard language. Implemented expression syntactic checking rules per SE-0492.

Major parts:
- Renamed @_section to @section and @_used to @used
- Removed the SymbolLinkageMarkers experimental feature
- Added parsing support for the old underscored names with deprecation warnings
- Updated all tests and examples to use the new attribute names
- Added syntactic validation for @section to align with SE-0492 (reusing the legality checker by @artemcm)
- Changed @DebugDescription macro to explicitly use a tuple type instead of type inferring it, to comply with the expression syntax rules
- Added a testcase for the various allowed and disallowed syntactic forms, `test/ConstValues/SectionSyntactic.swift`.
2025-10-22 16:05:39 -07:00
Artem Chikin
d8176a7e89 [Compile Time Values] Add syntactic verification of valid expressions in '@const' contexts
Syntactically verify that initializer expressions of '@const' variables and argument expressions to '@const' parameters consist strictly of syntactically-verifiable set of basic values and operations
2025-05-20 09:38:36 -07:00
Artem Chikin
f0831f38f3 Merge pull request #80997 from artemcm/OptimizedStdLibTestRestrict
[Test Only] Restrict '@const' test to optimized-stdlib builds
2025-04-23 14:02:35 -07:00
Anthony Latsis
a70fdde3fc AST: Quote attributes more consistently in DiagnosticsCommon.def 2025-04-22 18:23:40 +01:00
Artem Chikin
dfbfb821ad [Test Only] Restrict '@const' test to optimized-stdlib builds 2025-04-22 10:17:32 -07:00
Erik Eckstein
4d1df28de0 ConstantFolding: add constant folding for some floating point intrinsics
* `sitofp` signed integer to floating point
* `rint` round floating point to integral
* `bitcast` between integer and floating point

Constant folding `bitcast`s also made it necessary to rewrite constant folding for Nan and inf values, because the old code explicitly checked for `bitcast` intrinsics.
Relying on constant folded `bitcast`s makes the new version much simpler.

It is important to constant fold these intrinsics already in SIL because it enables other optimizations.
2025-04-01 18:13:01 +02:00
Artem Chikin
281f84da0f [Compile Time Values] Rewrite the 'Diagnose Unknown Compile Time Values' diagnostic pass in Swift 2025-03-28 10:30:07 -07:00
Artem Chikin
5753603472 [Compile Time Values] Mark currently-failing tests with requirement annotations 2025-03-27 14:33:38 -07:00
Artem Chikin
ac60612242 [Compile Time Values] Emit diagnostic note with parameter location on a non-@const argument to a @const parameter 2025-03-27 14:33:38 -07:00
Artem Chikin
114af54875 [Compile Time Values] Rebase on top of newly-added experimental feature for the '@const' attribute 2025-03-27 14:33:38 -07:00
Kuba Mracek
b8ef3ff779 Add test/ConstValues/Conditions.swift 2025-03-27 14:33:37 -07:00
Kuba Mracek
a925d6af20 Add tests 2025-03-27 14:33:37 -07:00