Commit Graph

10 Commits

Author SHA1 Message Date
Meghana Gupta
50f0fd232c Enable SILCombine of inject_enum_addr for empty types 2024-03-12 13:01:44 -07:00
Allan Shortlidge
e2bb7e8c8b SILOptimizer: Remove switch cases matching unavailable enum elements.
Unavailable enum elements cannot be instantiated at runtime without invoking
UB. Therefore the optimizer can consider a basic block unreachable if its only
predecessor is a block that terminates in a switch instruction matching an
unavailable enum element. Furthermore, removing the switch instruction cases
that refer to unavailable enum elements is _mandatory_ when
`-unavailable-decl-optimization=complete` is specified because otherwise
lowered IR for these instructions could refer to enum tag accessors that will
not be lowered, resulting in a failure during linking.

Resolves rdar://113872720.
2023-08-15 17:13:10 -07:00
Ben Cohen
e9d4687e31 De-underscore @frozen, apply it to structs (#24185)
* De-underscore @frozen for enums

* Add @frozen for structs, deprecate @_fixed_layout for them

* Switch usage from _fixed_layout to frozen
2019-05-30 17:55:37 -07:00
Michael Gottesman
adcfda6f6d [silgenpattern] When binding values, use a ManagedValue instead of an RValue to avoid implicitly exploding tuples.
In SILGenPattern, we need to be able to unforward cleanups when we explode
tuples. Thus we can't use RValue in SILGenPattern since it may implicitly
explode tuples (which without modifying RValue itself we can not
unforward). This patch removes a specific RValue usage that we can replace with
the use of a ManagedValue instead.

rdar://49903264
2019-05-16 12:41:08 -07:00
Slava Pestov
16d5716e71 SIL: Use the best resilience expansion when lowering types
This is a large patch; I couldn't split it up further while still
keeping things working. There are four things being changed at
once here:

- Places that call SILType::isAddressOnly()/isLoadable() now call
  the SILFunction overload and not the SILModule one.

- SILFunction's overloads of getTypeLowering() and getLoweredType()
  now pass the function's resilience expansion down, instead of
  hardcoding ResilienceExpansion::Minimal.

- Various other places with '// FIXME: Expansion' now use a better
  resilience expansion.

- A few tests were updated to reflect SILGen's improved code
  generation, and some new tests are added to cover more code paths
  that previously were uncovered and only manifested themselves as
  standard library build failures while I was working on this change.
2019-04-26 22:47:59 -04:00
Slava Pestov
9dd63a4918 AST: Use resilient access pattern for stored properties of resilient types visible via -enable-testing
Fixes <rdar://problem/45919829>.
2018-11-08 19:43:31 -05:00
Arnold Schwaighofer
1772e77064 IRGen: Fix multi-payload enum lowering
When we have a private resilient enum that is resilient because one of
its payloads is resilient but we have disabled resilience in the
context of lowering the enum as a class member (sigh), we must consider
it's payload's layout enum in the minimal domain (ignore the private
visibility) because we don't truly know the layout.

rdar://41308521
2018-06-25 15:03:28 -07:00
Arnold Schwaighofer
c7d4bd962d Add resilience tests 2018-05-22 08:59:00 -07:00
Slava Pestov
a05f6c80f6 IRGen: Use metadata accessors for types with resilient layout
If a struct has fixed layout but contains fields which are opaque,
or if the struct itself is opaque, use a metadata accessor function
instead of loading the metadata directly.

Let's say that A and B are two structs defined in the same module,
and B has a fixed size. This patch adds support for these two cases:

1) Fixed-layout struct A contains resilient struct B
2) Resilient struct A contains resilient struct B

In case 1),

a) Inside X: A is fixed-size and has constant metadata
 i) Direct metadata access can be performed on A and B
 ii) Direct field access can be performed on A and B
d) Outside X: B has an opaque layout
 i) Metadata accessor must be called for A and B
 ii) Fields of A do not have constant offsets, instead the offsets
     must be loaded from type metadata

Case 2) is the same as above except ii) does not apply, since fields
of resilient structs are manipulated via accessors.

Eventually, we will use metadata accessor functions for all public
struct and enum types.
2015-11-16 10:37:14 -08:00
Slava Pestov
19458cef2c IRGen: Preliminary resilient struct support
Add a new ResilientStructTypeInfo. This is a singleton since
all resilient structs have opaque payloads and are accessed
through value witness tables.

With this in place, flesh out IRGenModule::isResilient() and
use the new singleton to convert resilient structs.

Note that the old isResilient() was hard-coded to report that
all Clang-imported classes are "resilient". Now that this has
been unified with NominalTypeDecl::hasFixedLayout(), we will
report Clang-imported classes are "resilient" at the SIL level.
This should not introduce any semantic differences at this
point.

Unlike SIL, where currently resilient types are always resilient
even when used from the same module, IRGen is able to perform
direct manipulation of resilient structs from the current
module, since IRGen's type lowering has a resilience scope
plumbed through.

Note that we do not yet support laying out structs and classes
containing resilient fields -- this will come in a future patch.
2015-11-13 13:20:50 -08:00