Doug Gregor
1a1f79c0de
Introduce safety checkin for ConcurrentValue conformance.
...
Introduce checking of ConcurrentValue conformances:
- For structs, check that each stored property conforms to ConcurrentValue
- For enums, check that each associated value conforms to ConcurrentValue
- For classes, check that each stored property is immutable and conforms
to ConcurrentValue
Because all of the stored properties / associated values need to be
visible for this check to work, limit ConcurrentValue conformances to
be in the same source file as the type definition.
This checking can be disabled by conforming to a new marker protocol,
UnsafeConcurrentValue, that refines ConcurrentValue.
UnsafeConcurrentValue otherwise his no specific meaning. This allows
both "I know what I'm doing" for types that manage concurrent access
themselves as well as enabling retroactive conformance, both of which
are fundamentally unsafe but also quite necessary.
The bulk of this change ended up being to the standard library, because
all conformances of standard library types to the ConcurrentValue
protocol needed to be sunk down into the standard library so they
would benefit from the checking above. There were numerous little
mistakes in the initial pass through the stsandard library types that
have now been corrected.
2021-02-04 03:45:09 -08:00
Erik Eckstein
b42bce4ba4
stdlib: changes for the StringOptimization
...
To be able to constant fold string interpolation, the right semantic attributes must be in place.
Also, the interpolation's write function must be inlinable.
For the _typeName constant folding, a semantic attribute is required.
2020-07-27 21:32:56 +02:00
Ben Cohen
87df9961a5
Add fast string interpolation for metatypes ( #32113 )
2020-06-26 09:46:54 -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
Nicholas Maccharoli
cd5055711a
Fix syntax error in comment code
...
Closing parentheses is missing in the example code.
2019-05-06 01:38:47 +09:00
Michael Ilseman
89d18e1a3a
[String] Refactor helper code into UnicodeHelpers.swift.
...
Clean up some of the index assumptions, stick index-aware methods on
_StringGuts, and otherwise migrate code over to UnicodeHelpers.swift.
2018-11-04 10:42:40 -08:00
Michael Ilseman
4ab45dfe20
[String] Drop in initial UTF-8 String prototype
...
This is a giant squashing of a lot of individual changes prototyping a
switch of String in Swift 5 to be natively encoded as UTF-8. It
includes what's necessary for a functional prototype, dropping some
history, but still leaves plenty of history available for future
commits.
My apologies to anyone trying to do code archeology between this
commit and the one prior. This was the lesser of evils.
2018-11-04 10:42:40 -08:00
Brent Royal-Gordon
9bd1a26089
Implementation for SE-0228: Fix ExpressibleByStringInterpolation ( #20214 )
...
* [CodeCompletion] Restrict ancestor search to brace
This change allows ExprParentFinder to restrict certain searches for parents to just AST nodes within the nearest surrounding BraceStmt. In the string interpolation rework, BraceStmts can appear in new places in the AST; this keeps code completion from looking at irrelevant context.
NFC in this commit, but keeps code completion from crashing once TapExpr is introduced.
* Remove test relying on ExpressibleByStringInterpolation being deprecated
Since soon enough, it won’t be anymore.
* [AST] Introduce TapExpr
TapExpr allows a block of code to to be inserted between two expressions, accessing and potentially mutating the result of its subexpression before giving it to its parent expression. It’s roughly equivalent to this function:
func _tap<T>(_ value: T, do body: (inout T) throws -> Void) rethrows -> T {
var copy = value
try body(©)
return copy
}
Except that it doesn’t use a closure, so no variables are captured and no call frame is (even notionally) added.
This commit does not include tests because nothing in it actually uses TapExpr yet. It will be used by string interpolation.
* SE-0228: Fix ExpressibleByStringInterpolation
This is the bulk of the implementation of the string interpolation rework. It includes a redesigned AST node, new parsing logic, new constraints and post-typechecking code generation, and new standard library types and members.
* [Sema] Rip out typeCheckExpressionShallow()
With new string interpolation in place, it is no longer used by anything in the compiler.
* [Sema] Diagnose invalid StringInterpolationProtocols
StringInterpolationProtocol informally requires conforming types to provide at least one method with the base name “appendInterpolation” with no (or a discardable) return value and visibility at least as broad as the conforming type’s. This change diagnoses an error when a conforming type does not have a method that meets those criteria.
* [Stdlib] Fix map(String.init) source break
Some users, including some in the source compatibility suite, accidentally used init(stringInterpolationSegment:) by writing code like `map(String.init)`. Now that these intializers have been removed, the remaining initializers often end up tying during overload resolution. This change adds several overloads of `String.init(describing:)` which will break these ties in cases where the compiler previously selected `String.init(stringInterpolationSegment:)`.
* [Sema] Make callWitness() take non-mutable arrays
It doesn’t actually need to mutate them.
* [Stdlib] Improve floating-point interpolation performance
This change avoids constructing a String when interpolating a Float, Double, or Float80. Instead, we write the characters to a fixed-size buffer and then append them directly to the string’s storage.
This seems to improve performance for all three types, but especially for Double and Float80, which cannot always fit into a small string when stringified.
* [NameLookup] Improve MemberLookupTable invalidation
In rare cases usually involving generated code, an overload added by an extension in the middle of a file would not be visible below it if the type had lazy members and the same base name had already been referenced above the extension. This change essentially dirties a type’s member lookup table whenever an extension is added to it, ensuring the entries in it will be updated.
This change also includes some debugging improvements for NameLookup.
* [SILOptimizer] XFAIL dead object removal failure
The DeadObjectRemoval pass in SILOptimizer does not currently remove reworked string interpolations as well as the old design because their effects cannot be described by @_effects(readonly). That causes a test failure on Linux. This change temporarily silences that test. The SILOptimizer issue has been filed as SR-9008.
* Confess string interpolation’s source stability sins
* [Parser] Parse empty interpolations
Previously, the parser had an odd asymmetry which caused the same function to accept foo(), but reject “\()”. This change fixes the issue.
Already tested by test/Parse/try.swift, which uses this construct in one of its throwing interpolation tests.
* [Sema] Fix batch-mode-only lazy var bug
The temporary variable used by string interpolation needs to be recontextualized when it’s inserted into a synthesized getter. Fixes a compilation failure in Alamofire.
I’ll probably follow up on this bug a bit more after merging.
2018-11-02 19:16:03 -07:00
Erik Little
863f3a19ff
Rename @effects to @_effects
...
@effects is too low a level, and not meant for general usage outside
the standard library. Therefore it deserves to be underscored like
other such attributes.
2018-06-06 12:53:03 -04:00
Slava Pestov
e1f50b2d36
SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline
2018-03-30 21:55:30 -07:00
Max Moiseev
53b8419279
[stdlib] Make all the stdlib APIs @_inlineable
...
This change in theory should allow us to remove a special stdlib-only
sil-serialize-all compilation mode.
<rdar://problem/34138683>
2017-09-29 11:26:56 -07:00
Nate Cook
b7af9bfe83
[stdlib] Remove SeeAlso tags
2017-06-13 11:23:51 -05:00
Roman Levenstein
29ad714bb7
Annotate stdlib functions to get a good performance even in resilient mode, when -sil-serialize-all is disabled
...
This commit mostly improves the performance of arrays and ranges.
It does not cover Strings, Dictionaries and Sets yet.
2017-03-16 19:46:11 -07:00
practicalswift
3e40296cfa
[gardening] Fix inconsistent headers
2017-02-13 15:21:52 +01:00
Doug Gregor
12fc2d22bf
[Standard library] de-GYB string interpolation. NFC
2017-02-08 21:01:18 -08:00
Doug Gregor
bb365b4657
Revert "[Standard library] de-GYB string interpolation. NFC"
...
This reverts commit 658f244188 .
2017-02-08 13:38:10 -08:00
Doug Gregor
0b4261cae1
Revert "[Standard library] Remove some gyb-related cruft from string interpolation."
...
This reverts commit d0811cc318 .
2017-02-08 13:38:08 -08:00
Doug Gregor
d0811cc318
[Standard library] Remove some gyb-related cruft from string interpolation.
...
NFC
2017-02-01 10:51:02 -08:00
Doug Gregor
658f244188
[Standard library] de-GYB string interpolation. NFC
2017-01-30 10:16:24 -08:00