Commit Graph

1367 Commits

Author SHA1 Message Date
Xi Ge fe7fdce8ee IRGen: lower hidden C-type layout to TrivialHiddenTypeInfo
When a struct has stored properties from an internal bridging header,
add @_hasHiddenStoredProperties to force address-only on both library
and client sides, and resolve layout via the defining module's
HiddenTypeLayouts table in IRGen.

Making these structs loadable is challenging because library and client
must agree on the register-passing scheme (which registers carry which
fields), and that scheme depends on the full type structure that the
client cannot see. Address-only sidesteps this by passing everything
indirectly.

Tests: hidden-type-irgen.swift verifies the Client's IR has correct
alloca sizes/alignments and outlined copy witnesses without referencing
hidden C symbols. hidden-type-runtime.swift builds a dylib + executable
and verifies values round-trip correctly across the boundary at runtime.
2026-05-27 22:28:27 -07:00
Kavon Farvardin 19119ad88a introduce @_preInverseGenerics(except:)
@_preInverseGenerics(except: <inverses>) is an extension of the existing
@_preInverseGenerics attribute that provides selective control over which
inverse requirements are mangled into a declaration's symbol name.

While the bare @_preInverseGenerics strips all inverse constraints
(~Copyable and ~Escapable) from mangling, the 'except:' form allows specific
inverses to be retained. This is needed when a type like Span already had
~Copyable mangled into its ABI-stable symbols and now needs to retroactively
adopt ~Escapable without changing those existing symbols. You can now express
that with `@_preInverseGenerics(except: ~Copyable)` to strip-out every inverse
except ~Copyable to preserve the pre-existing ~Copyable-containing symbols.

It requires the new experimental feature `PreInverseGenericsExcept`.

rdar://176395527
2026-05-14 18:27:00 -07:00
Xi Ge 08776427a1 [AST] Introduce HiddenType for mangled-name placeholders
HiddenType is a new TypeBase subclass that carries a mangled name
without leaking the actual type definition. It serves as a type-slot
placeholder for stored-property types that have been elided from a
serialized binary module, so that the client side can either

(1) resolve this mangled name to the real type if the client has access to the owning module, or

(2) use the mangled name as a key to query abstract layout information also serialized in the binary module.

As an example — a library with a hidden field of a bridging-imported type:

```
    // Utility.h (internal bridging header)
    //   typedef struct { int value; } Wrapper;

    public struct S {
      private var w: Wrapper
      public var weight: Double
    }

  In the serialized module, the client's view reconstructs as:

    public struct S {
      private var w: @_hidden("$sSo7Wrappera")
      public var weight: Double
    }
```
2026-05-12 17:13:14 -07:00
Aidan Hall d966ce12ef Merge pull request #88768 from aidan-hall/lifedep-refactored-print
Unified lifetime printing for Swift, SIL and AST dumps
2026-05-08 22:24:00 +01:00
Artem Chikin a7bbffd953 Merge pull request #88205 from artemcm/DiagnoseAttr
[Source Warning Control] Rename `@warn` to `@diagnose` & prevent printing it in Textual Interfaces
2026-05-07 16:52:22 +01:00
Aidan Hall b134e3f9d9 Lifetimes: Include in AST type dumps 2026-05-06 11:02:51 +01:00
Michael Gottesman f0e724e4d8 [ast] Dump out if ParamFlags has sending. 2026-04-30 10:02:19 -07:00
Artem Chikin 866371d73e [Source Warning Control] Rename '@warn' to '@diagnose'
Resolves rdar://173774670
2026-04-29 10:39:25 +01:00
Konrad Malawski c0a6508c46 fix ast dumper printing of NonisolatedConcurrent 2026-04-28 09:21:46 -07:00
Konrad Malawski c8e9b5bd9e Cleanups: remove redundant special-casing, fix rebase-dropped test content
- Remove redundant isCrossingCheck ternary in MismatchedIsolatedConformances:
  printStringForDiagnostics now correctly returns "@concurrent" for
  NonisolatedConcurrent and "nonisolated" for Nonisolated, so the manual
  override is unnecessary. Remove the isCrossingCheck field entirely.
- Change isolated_conformance_wrong_domain and
  isolated_conformance_may_cross_isolation diagnostics to accept
  ActorIsolation directly instead of StringRef, letting the diagnostic
  engine call printForDiagnostics.
- Rename ASTDumper flag from "isolated_to_caller_isolation" to
  "nonisolated_nonsending".
- Restore SIL test CHECK lines that lost @caller_isolated annotations
  during rebase conflict resolution (optimize_hop_to_executor.sil,
  attr_execution tests, SILGen tests, Serialization tests).
- Apply caller_isolation_inheriting -> nonisolated(nonsending) rename
  to restored test files.
2026-04-28 09:21:46 -07:00
Konrad Malawski 4e4769de49 Rename stale CallerIsolated to NonisolatedNonsending 2026-04-28 09:21:23 -07:00
Konrad Malawski 003028c17c more rename followups for isNonisolated and the enum change 2026-04-28 09:21:23 -07:00
Konrad Malawski 77ac31d946 Rename to ActorIsolation::Kind::Nonisolated*Concurrent* 2026-04-28 09:21:23 -07:00
Konrad Malawski 3beefe5bd8 Rename CallerIsolationInheriting -> NonisolatedNonsending 2026-04-28 09:21:23 -07:00
Hamish Knight 76ec88651f [ASTDumper] Dump original expr for unresolved GenericArgumentExprTypeRepr
Make sure we still dump the parsed expression prior to type-checking.
2026-03-24 12:34:10 +00:00
Slava Pestov 3c2720b8bc AST: Introduce JoinType and MeetType singletons
These will be used internally by the type checker to represent bindings
that are the joins and meets of types involving type variables. They
will not appear anywhere outside of the bindings code---so you won't
see them in expressions, or matchTypes(), etc.
2026-03-21 08:48:47 -04:00
Artem Chikin b6e9e5c7ba [Literal Expressions] Introduce expression-based generic arguments
Introduce new syntax for parsing arbitrary integer literal expressions for generic value arguments:
```swift
InlineArray<(<Expr>), T>
[(<Expr>) of T]
```
Which, for now, will co-exist alongside the current syntax of simple integer literals.

Replace `IntegerTypeRepr` with `GenericArgumentExprTypeRepr`, a new `TypeRepr` node that wraps arbitrary expressions in generic argument positions (e.g., `InlineArray<(1 + 3), Int>`). The node tracks resolution state, distinguishing whether the expression resolved to a type or an integer value.

Key changes:
- Parse parenthesized generic arguments as expressions
- Recover and distinguish types from integer expressions in `resolveGenericArgumentExprTypeRepr`.
- When the `LiteralExpressions` feature is enabled, type-check and constant-fold expressions to integer values
- Extract `PreCheckTarget` into a public header to expose `simplifyTypeExpr` for use during type resolution

Resolves rdar://168005391
2026-02-24 14:10:39 +00:00
Artem Chikin ae826a1501 Represent Integer Generic Values as an expression in the 'IntegerTypeRepr'
Laying the groundwork for follow-up changes which will allow us to use constant/literal expressions in place of a simple integer literal.
2026-02-23 15:14:20 +00:00
Becca Royal-Gordon 31f99c2f55 Ignore generic context when module selector used
Normally, an unbound reference to a generic type within its own context is automatically bound to the identity generic arguments:

```
struct G<T> {
    typealias TA = G    // as if you wrote G<T>
}
```

Module selectors normally disable this kind of contextual behavior; make sure that this is not an exception.

To pipe the information needed to do this through the constraint solver, we extend FunctionRefInfo to remember whether a module selector was used.
2026-02-17 18:21:37 -08:00
elsa c4cc1b5e15 Merge pull request #87266 from elsakeirouz/print-foreach-desugared-statement
[ASTDumper] always label ForEachStmt's desugared BraceStmt
2026-02-17 18:08:27 +01:00
Elsa Keirouz 76b01e5d6c [ASTDumper] always label ForEachStmt's desugared BraceStmt 2026-02-16 21:08:19 +01:00
Hamish Knight 80edad2d2e [ASTDumper] Handle sendable dependence
Dump the sendable dependent type if present.
2026-02-16 14:37:58 +00:00
Tony Allevato 5e68b7cbac Merge pull request #85845 from allevato/json-ast-conformance-modules
[ASTDumper] Print the USR for a protocol conformance's declaring context.
2026-02-11 20:17:07 -05:00
Becca Royal-Gordon b0bd6c711c Merge pull request #86905 from beccadax/mod-squad-not-for-export-2 2026-02-11 02:28:08 -08:00
Becca Royal-Gordon cbad1d8a18 Tweak export_as behavior with submodules
In #86859, I modified the way `export_as` names are used in private module interfaces so that the `export_as` name is used when that module has been imported. This turns out to be slightly too aggressive in a specific scenario where a submodule of the export_as module imports a submodule of the real module—the compiler ends up using the export name even though the resulting lookup won’t actually work.

Modify the logic for deciding whether to use an exported module name so that it not only checks whether the export_as module has been loaded, but also whether the specific module or submodule the declaration belongs to is (possibly transitively) imported by that module.

Fixes rdar://167874630 (harder).
2026-02-10 15:49:47 -08:00
Artem Chikin 1e5ba5fca8 [Literal Expressions] Add support for literal expressions in enum raw values
Modify relevant portions of the type-checker and parser to allow, when the 'LiteralExpressions' experimental feature is enabled, for arbitrary integer-typed expressions in enum raw value specifiers. These expressions will be type-checked and constant-folded into an integer literal expression, keeping the current interface of 'EnumElementDecl' consistent for clients.

Previously, 'EnumRawValuesRequest' had two different "modes" which were discerned based on typechecking stage (structural | interface), where the former had the request compute all raw values, both user-specified literal expressions and computing increment-derived values as well; the latter would also type-check the user-specified expressions and compute their types.
- With the need to have enum case raw values support arbitrary integer expressions, the request ('EnumRawValuesRequest') has been refactored and simplified to *always* both compute all case raw values and perform type-checking of user-specified raw value expressions. This is done in order to allow the AST-based constant-folding infrastructure ('ConstantFoldExpression' request) to run on the expressions. Constant folding is invoked during the evaluation of 'EnumRawValuesRequest' on all user-specified raw value expressions, in order to be able to compute subsequent increment values and ensure the expressions are foldable. If they are not, i.e. if constant folding fails, a relevant diagnostic will be emitted.
- 'EnumElementDecl' continues to store the raw value expression, which is no longer a 'LiteralExpr' but rather an 'Expr'; however, the getter ('getRawValueExpr') continues to return a 'LiteralExpr' by invoking the constant-folding request on the stored value, which is guaranteed to return a cached result from a prior invocation in 'EnumRawValuesRequest', assuming it succeeded.
- Furthermore, the 'structural' request kind was previously not cached, whereas now because the request must always do the complete type-checking work, it is always cached.

Resolves rdar://168005520
2026-02-10 09:43:07 +00:00
Artem Chikin 2f0ba5820c Merge pull request #86500 from artemcm/LiteralExpressions
[Literal Expressions] Add support for simple constant-folded literal expressions
2026-02-09 16:20:09 +00:00
Artem Chikin 0bbd35242c [Literal Expressions] Add support for simple constant-folded literal expressions
This change adds an experimental feature 'LiteralExpressions` which allows for use of simple binary expressions of integer type composed of literal value operands.

For now, such literal expressions are only supported in initializers of '@section` values.
2026-02-09 11:35:45 +00:00
Kavon Farvardin ae77ba81e3 Merge pull request #87013 from kavon/revert-84789
Back out #84789 after additional testing
2026-02-06 02:58:00 -08:00
Kavon Farvardin d5f9a1eeeb Revert "Merge pull request #84789 from nickolas-pohilets/mpokhylets/fix-82618"
This reverts commit b633bd37ac, reversing
changes made to b27bb64b03.
2026-02-05 11:34:59 -08:00
Kavon Farvardin 4a7cedcf1e Reparenting: introduce new attributes
A protocol that's been reparented declares it
by writing `@reparented` in its inheirtance clause
for each new parent. You can introduce a `@reparented`
parent to a pre-existing ABI-stable protocol's
inheritance hierarchy.

Only protocols declared to be  `@reparentable` can be
used to reparent other protocols. Adding or removing
the `@reparentable` attribute is ABI-breaking, as it
effects the type metadata layout. Thus, reparentable
protocols must be born as such to use them with
protocols that are already ABI-stable.

This set of changes does not include the actual
implementation of ABI-stable reparenting.
2026-02-03 16:39:19 -08:00
Joe Groff 0f3ddfbcc8 Merge pull request #86545 from jckarter/builtin-borrow
`Builtin.Borrow` implementation
2026-01-26 07:32:31 -08:00
elsa 5e9f215f31 Merge pull request #86010 from elsakeirouz/rework-for-each-desugar
Rework ForEachStmt Desugaring
2026-01-24 13:55:51 +00:00
Joe Groff bc166d5a8c Add a Builtin.Borrow type.
This will represent the layout of a borrow of a value.
2026-01-23 07:46:50 -08:00
Elsa Keirouz f7c21941b8 [AST] ForEachStmt: rename sequence getter/setter 2026-01-23 15:17:29 +00:00
Elsa Keirouz d54a572f7f [Sema] desugar ForEachStmt at AST level 2026-01-23 15:17:29 +00:00
Elsa Keirouz 27cef65d56 [AST] Introduce opaque AST nodes 2026-01-23 15:17:28 +00:00
Michael Gottesman 605f8b8bc8 Merge pull request #86591 from gottesmm/pr-96614c5460cd1078f51ac70cd6c119d8f0ea8910
[ast] In ASTDumper, print out flags for unspecified and nonisolated(unsafe) isolation.
2026-01-22 14:24:40 -08:00
Mykola Pokhylets 551a2cec6c Using ClosureExpr instead of ConversionPair in CollectionUpcastConversionExpr 2026-01-20 14:49:56 +01:00
Michael Gottesman 47cb855806 [ast] In ASTDumper, print out flags for unspecified and nonisolated(unsafe) isolation.
This makes it clear in any context the isolation instead of the reader having to
guess if we forgot to print the isolation or not. A dumper should be more
verbose than less verbose.
2026-01-15 17:55:13 -08:00
Tim Kientzle adec1f6cbe Merge pull request #86277 from tbkka/tbkka-rdar149303951-try1
[SE-0474] Implement final `yielding borrow`/`yielding mutate` naming for coroutine accessors
2026-01-09 08:52:21 -08:00
Kavon Farvardin 458b62c9ed introduce UnderscoreOwned feature
This experimental feature allows you to override the default behavior
of a 'get' returning a noncopyable type, so that it returns an owned
value rather than a borrow, when that getter is exposed in opaque
interfaces like protocol requirements or resilient types.

resolves rdar://157318147
2026-01-06 16:39:54 -08:00
Tim Kientzle 8eabeeb8ca [SE-0474] Read2/Modify2 => YieldingBorrow/YieldingMutate
This updates a large number of internal symbols, function names,
and types to match the final approved terminology.  Matching the
surface language terminology and the compiler internals should
make the code easier for people to understand into the future.
2026-01-03 16:05:12 -08:00
Artem Chikin 8e97cb4d8d Implement support for unified warning group behavior queries per-diagnostic
Unified across module-wide configuration flags (`-Wwarning`, `-Werror`, etc.) and syntactic configuration attribute `@warn`.
2025-12-12 10:14:20 -08:00
Artem Chikin e593fd97a0 Add parsing for a declaration attribute '@warn' for source-level warning group behavior control 2025-12-12 10:14:14 -08:00
Tony Allevato 770a6b2869 [ASTDumper] Print the USR for a protocol conformance's declaring context.
It's useful to know where a conformance is coming from when doing semantic
analysis. The main motivating use case is this: imagine a module that
declares a type:

```swift
// SomeTypeModule
struct SomeType {}
```

Then a second module that adds a conformance:

```swift
// SomeTypeConformanceModule
extension SomeType: @retroactive Codable {
  // implementation of requirements
}
```

Then a third module that uses that conformance:

```swift
import SomeTypeModule
import SomeTypeConformanceModule

func f() {
  _ = try? JSONEncoder().encode(SomeType())
}
```

There's currently nothing in the printed AST that indicates that the import
of `SomeTypeConformanceModule` is required. Printing the declaring context
for conformances lets us get that signal from the substitution map at the
call site in `f()`.

Also removed a place where we redundantly output `retroactive`.
2025-12-04 15:45:14 -05:00
Tony Allevato 88081a9308 Merge pull request #85807 from allevato/more-json-ast-fixes-2
[ASTDumper] Fix malformed JSON for `async let _ = ...`.
2025-12-03 08:22:29 -05:00
Hamish Knight 019520b25f Merge pull request #85740 from hamishknight/out-of-place
Rework emission of EditorPlaceholderExprs
2025-12-02 23:25:40 +00:00
Tony Allevato 7ec3789cf7 [ASTDumper] Fix malformed JSON for async let _ = ....
By calling `printCommon` twice, this inserts a JSON object into
another JSON object without a key. This asserts inside LLVM's
JSON helper, but only if the compiler is built with assertions
enabled (which Xcode's compiler doesn't).

This also fixes the S-expression version, which is similarly busted:

```
(pattern_entry
  (async_let  type="Int"              (pattern_any type="Int")
  (original_init=call_expr type="Int" ...
```
2025-12-02 16:26:09 -05:00
Hamish Knight ae82b29e35 Rework emission of EditorPlaceholderExprs
Rather than synthesizing a semantic expression to emit, add a compiler
intrinsic to the stdlib that is simple enough to just SILGen the
emission.
2025-11-30 11:12:39 +00:00