Commit Graph

2441 Commits

Author SHA1 Message Date
Slava Pestov
60615b8a52 SIL: Handle captured environments in SILFunction::mapTypeIntoContext() 2024-05-16 23:00:44 -04:00
Slava Pestov
c1ce0d72c2 SIL: Store captured environments in SILFunction 2024-05-16 23:00:44 -04:00
Erik Eckstein
f3dafbff2f SIL: make unchecked_ref_cast buildable in a global variable initializer 2024-05-16 21:34:35 +02:00
Michael Gottesman
e3e78ad6bb [sending] Change the internals of sending to be based around 'sending' instead of 'transferring'.
We still only parse transferring... but this sets us up for adding the new
'sending' syntax by first validating that this internal change does not mess up
the current transferring impl since we want both to keep working for now.

rdar://128216574
2024-05-16 12:20:45 -07:00
Augusto Noronha
e5a1d61ed8 Merge pull request #73145 from augusto2112/keep-for-deb-def
Fix functions not being kept for debugger
2024-05-16 11:32:43 -07:00
Ellie Shin
1257db7342 Merge pull request #73566 from apple/elsh/sil-new-attr
[SIL] Add [serialized_for_package] to control package-wide resilience domain in Package-CMO.
2024-05-16 10:17:35 -07:00
Ellie Shin
0e88dc2742 Initialize SerializedForPackage bit field 2024-05-15 21:44:36 -07:00
Ellie Shin
e632c5ec96 -Add package-cmo check to bypassResilienceInPackage method.
-Fix SILDeclRef getLinkageLimit() for GlobalAccessor to return
Limit::None if bypassResilienceInPackage is enabled.
2024-05-15 16:25:16 -07:00
Ellie Shin
2d81d0f2c7 [SIL] Add a new attribute [serialized_for_package] to support
package-wide resilience domain if Package CMO is enabled.

The purpose of the attribute includes:
- Indicates that certain types such as loadable types are
allowed in serialized functions in resiliently built module
if the optimization is enabled, which are otherwise disallowed.
- Used during SIL deserialization to determine whether such
functions are allowed.
- Used to determine if a callee can be inlined into a caller
that's serialized without package-cmo, e.g. with an explicit
annotation like @inlinable, where the callee was serialized
due to package-cmo.

Resolves rdar://127870822
2024-05-15 12:43:15 -07:00
Augusto Noronha
529845056b Fix functions not being kept for debugger
At Onone, many types of functions (anything user written, compiler
generated setters and getters, etc), should be kept in the final
binary so they're accessible by the debugger.

rdar://126763340
2024-05-14 10:31:44 -07:00
Andrew Trick
4272552080 Merge pull request #73577 from atrick/fix-init-objc-block
Fix initialization of imported ObjC block types.
2024-05-13 16:57:00 -07:00
Michael Gottesman
4789cc7e55 Merge pull request #73556 from gottesmm/rdar127295657_127844737
[region-isolation] When inferring isolation for an argument, handle non-self isolated parameters as well as self parameters that are actor isolated.
2024-05-13 11:18:51 -07:00
Emil Pedersen
15cab3a19f Merge pull request #73555 from Snowy1803/complete-getvarinfo
[DebugInfo] Return complete variable info from getVarInfo by default
2024-05-13 10:32:43 -07:00
Andrew Trick
c112e03a32 Fix initialization of imported ObjC block types.
This fixes a SIL ownership verification error when importing structs like:

typedef bool (^boolBlock)(void);

struct objc_bool_block {
  __unsafe_unretained boolBlock block;
};

Fixes rdar://126142109 (Found an operand with a value that is not compatible
with the operand's operand ownership kind map)
2024-05-10 17:45:11 -07:00
Emil Pedersen
0be63d0422 [DebugInfo] Return complete variable info from getVarInfo by default
getVarInfo() now always returns a variable with a location and scope.
To opt out of this change, getVarInfo(false) returns an incomplete variable.
This can be used to work around bugs, but should only really be used for
printing.

The complete var info will also contain the type, except for debug_values,
as its type depends on another instruction, which may be inconsistent if
called mid-pass.

All locations in debug variables are now also stripped of flags, to avoid
issues when comparing or hashing debug variables.
2024-05-10 16:12:56 -07:00
Michael Gottesman
085f3d745e [region-isolation] Return the old way of printing ActorIsolation for use when printing SIL instructions. 2024-05-10 15:59:25 -07:00
Michael Gottesman
9bfb3b7ee7 [region-isolation] Some small gardening updates in preparation for the next commit.
Specifically, I added a few helper methods and improved the logging printing.
This all makes the next commit a more focused commit.
2024-05-10 15:33:44 -07:00
Egor Zhdan
0971654de2 Merge pull request #73513 from apple/egorzhdan/const-ref-bool-crash
[cxx-interop] Do not crash when passing `Bool` as `const T&` parameter
2024-05-09 18:44:37 +01:00
Egor Zhdan
5b5ffde79e [cxx-interop] Do not crash when passing Bool as const T& parameter
The type bridging logic assumed that if a value of type `Swift.Bool` is passed to a Clang function as an argument, then the type of the parameter must be a Clang built-in type (usually `_Bool`). This is not always correct. For instance, the type might be a templated const reference.

rdar://125508505
2024-05-09 15:28:33 +01:00
Stephen Canon
396b055369 Implement Builtin.freeze for integer and integer-vector types. (#73519)
* Implement Builtin.freeze for integer and integer-vector types.

https://llvm.org/docs/LangRef.html#freeze-instruction

> If the argument is undef or poison, ‘freeze’ returns an arbitrary, but fixed, value of type ‘ty’. Otherwise, this instruction is a no-op and returns the input argument. All uses of a value returned by the same ‘freeze’ instruction are guaranteed to always observe the same value, while different ‘freeze’ instructions may yield different values.

It's most importation for integer and integer-vector types because floating-point results are generally not poison (except in the case of conversion from poison integer values).
However, we might want to implement this for other types as well in the future.

* Make builtin.freeze TrivialUse

Also fix filecheck patterns for its test to work with asserts build.
2024-05-09 06:41:02 -04:00
Ellie Shin
0f606e76cb Merge pull request #73478 from apple/elsh/pcmo-res
Support generating loadable types in serialized function when package-cmo is enabled.
2024-05-08 16:08:13 -07:00
Adrian Prantl
9a2e245678 Merge pull request #73504 from Snowy1803/rdar127348128
[DebugInfo] Fix verifier crash for complex switch
2024-05-08 16:06:00 -07:00
Ellie Shin
9b28969e2d To support serializing functions containing loadable types in a resiliently built
module when package serialization is enabled, return maximal resilience expansion
in SILFunction::getResilienceExpansion(). This allows aggregate types to be generated
as loadable SIL types which otherwise are address-only in a serialized function.
During type lowering, opaque flag setting is also skipped if package serialization
is enabled.

Resolves rdar://127400743
2024-05-08 05:01:25 -07:00
Emil Pedersen
6136183c33 [DebugInfo] Fix loss of VarDecl in debug values for salvaged stores
When a store is salvaged, its debug_value will have two locations:
the location of the store, attached to the debug_value instruction,
and the location of the variable, attached to the SILDebugVariable.

The getDecl function was using the location of the store, instead
of the location of the variable, and so was returning nullptr.
2024-05-07 14:34:18 -07:00
Emil Pedersen
4bc672e7c1 [DebugInfo] Deduplicate location and scope in debug variables (NFC) 2024-05-07 13:58:57 -07:00
nate-chandler
bcd08c0c9a Merge pull request #73235 from nate-chandler/bitwise-copyable/enable
[BitwiseCopyable] Promote to feature.
2024-05-04 10:16:40 -07:00
Nate Chandler
06921cfe84 [SIL] Hollow out Builtin.copy, deprecate _copy.
The copy operator has been implemented and doesn't use it.  Remove
`Builtin.copy` and `_copy` as much as currently possible.

Source compatibility requires that `_copy` remain in the stdlib.  It is
deprecated here and just uses the copy operator.

Handling old swiftinterfaces requires that `Builtin.copy` be defined.
Redefine it here as a passthrough--SILGen machinery will produce the
necessary copy_addr.

rdar://127502242
2024-05-03 15:56:25 -07:00
Slava Pestov
625436af05 Merge pull request #73393 from slavapestov/pack-expansion-closures-part-3
SIL type lowering support for closures that capture pack element archetypes
2024-05-02 19:43:24 -04:00
Emil Pedersen
bf58b030c5 Merge pull request #73387 from Snowy1803/allocbox-fix
[DebugInfo] Fix loss of variables at -Onone
2024-05-02 12:39:17 -07:00
Slava Pestov
fa89c52556 SIL: Introduce TypeConverter::getForwardingSubstitutionsForLowering() 2024-05-02 14:28:30 -04:00
Slava Pestov
fa2cd6cbcc SIL: Support element archetypes inside lowerCaptureContextParameters() 2024-05-02 13:40:54 -04:00
Slava Pestov
1cad5f9350 SIL: Plumb pack element captures through type lowering 2024-05-02 13:40:54 -04:00
Slava Pestov
70fb18e799 SIL: Rename misleading getFunctionInterfaceTypeWithCaptures() 2024-05-02 13:40:54 -04:00
Slava Pestov
9e13db09e0 SIL: buildThunkType() uses (new) LocalRequirementArchetypeCollector 2024-05-01 15:35:24 -04:00
Slava Pestov
865b155f2e SIL: Thunks that capture local environments must also capture the primary environment
I suspect there are latent bugs here with generic-class-constrained existentials,
same-element requirements involving packs, etc. We can't assume that the
local archetypes don't have "hidden" dependencies on the outer parameters
that are not encoded in the thunk's interface type.
2024-04-30 22:45:41 -04:00
Slava Pestov
97d95218f8 AST: Record captured generic environments in CaptureInfo 2024-04-30 21:38:15 -04:00
Emil Pedersen
f6232a937d [DebugInfo] Fix wrong scope being used in AllocBoxToStack 2024-04-30 16:29:49 -07:00
Akira Hatanaka
428fe21855 [SILGen] Fix a bug where the wrong convention was being used for computing the type of a closure thunk (#73299)
The ObjC selector family convention was being used instead of the C
function type convention.

rdar://127090209
2024-04-29 18:03:59 -07:00
Nate Chandler
5307ac666e [SIL] Permit end_borrow(begin_apply). 2024-04-25 17:03:41 -07:00
Nate Chandler
121b2faccc [NFC] SIL: Add ValueBase::isBeginApplyToken.
Forwards to the member function of the same name on
MultipleValueInstructionResult.
2024-04-25 17:03:11 -07:00
Nate Chandler
b1fbe4ea91 [BitwiseCopyable] Remove underscore. 2024-04-25 11:44:15 -07:00
Nate Chandler
ed5c7ef7ae [BitwiseCopyable] Promote to feature.
SE-0426 was accepted.
2024-04-24 15:52:20 -07:00
Michael Gottesman
025902fa99 [sil] Add a SILDeclRef field to SILFunction, have SILGen set it, and teach SILFunction how to use the field to get the SourceFile associated with the SILFunction. 2024-04-23 11:45:36 -05:00
Yuta Saito
ae74a57345 Merge pull request #73162 from kateinoigakukun/yt/indirect-err-result-conv 2024-04-23 00:50:02 +09:00
Slava Pestov
e342a38b87 Sema: Convert TypeChecker::computeCaptures() into two requests
We now compute captures of functions and default arguments
lazily, instead of as a side effect of primary file checking.

Captures of closures are computed as part of the enclosing
context, not lazily, because the type checking of a single
closure body is not lazy.

This fixes a specific issue with the `-experimental-skip-*` flags,
where functions declared after a top-level `guard` statement are
considered to have local captures, but nothing was forcing these
captures to be computed.

Fixes rdar://problem/125981663.
2024-04-20 22:16:25 -04:00
Yuta Saito
eeb62b056b [SILGen] Create thunks for non-throwing -> indirect error result conversions
When a non-throwing function is passed to a function that expects a
throwing function with an indirect error result, we need to create a
thunk because the indirect error result pointer is passed as an extra
trailing parameter. Extra trailing parameters except for `swifterror`
and `swiftself` are not allowed on some platforms like WebAssembly, so
they need to be called as exactly the same function signature.

```swift
func passThrough<X>(_ c: () throws(X) -> Void) throws(X) {
  try c()
}
func neverThrow() {}
passThrough(neverThrow)
```
2024-04-20 06:45:15 +00:00
Slava Pestov
3e637b0afb Merge pull request #73129 from slavapestov/local-function-isolation-change
Local functions inherit isolation from context instead of captures
2024-04-19 08:32:46 -04:00
Slava Pestov
05bcc25f7b SIL: Local functions should inherit isolation from context
If the outer context is actor isolated, we need to force a capture the
actor variable, since otherwise it might not appear in the capture list.
2024-04-18 23:26:17 -04:00
Slava Pestov
24857abf73 SIL: Remove unused DeclContext in getLoweredLocalCaptures() 2024-04-18 23:07:06 -04:00
Slava Pestov
d222470a0b AST: Remove unused methods from CaptureInfo 2024-04-18 22:47:23 -04:00