Skip to content

Commit 0ea3ab1

Browse files
Merge pull request #4306 from swiftwasm/main
[pull] swiftwasm from main
2 parents 68e80e4 + 5674086 commit 0ea3ab1

File tree

101 files changed

+10157
-7877
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+10157
-7877
lines changed

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ int dumpSDKContent(const CompilerInvocation &InitInvok,
816816
const llvm::StringSet<> &ModuleNames,
817817
StringRef OutputFile, CheckerOptions Opts);
818818

819-
void dumpModuleContent(ModuleDecl *MD, StringRef OutputFile, bool ABI);
819+
void dumpModuleContent(ModuleDecl *MD, StringRef OutputFile, bool ABI, bool Empty);
820820

821821
/// Mostly for testing purposes, this function de-serializes the SDK dump in
822822
/// dumpPath and re-serialize them to OutputPath. If the tool performs correctly,

include/swift/AST/Decl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5504,6 +5504,7 @@ enum class ParamSpecifier : uint8_t {
55045504
class ParamDecl : public VarDecl {
55055505
friend class DefaultArgumentInitContextRequest;
55065506
friend class DefaultArgumentExprRequest;
5507+
friend class DefaultArgumentTypeRequest;
55075508

55085509
enum class ArgumentNameFlags : uint8_t {
55095510
/// Whether or not this parameter is destructed.
@@ -5524,6 +5525,9 @@ class ParamDecl : public VarDecl {
55245525
struct alignas(1 << StoredDefaultArgumentAlignInBits) StoredDefaultArgument {
55255526
PointerUnion<Expr *, VarDecl *> DefaultArg;
55265527

5528+
/// The type of the default argument expression.
5529+
Type ExprType;
5530+
55275531
/// Stores the context for the default argument as well as a bit to
55285532
/// indicate whether the default expression has been type-checked.
55295533
llvm::PointerIntPair<Initializer *, 1, bool> InitContextAndIsTypeChecked;
@@ -5641,6 +5645,10 @@ class ParamDecl : public VarDecl {
56415645
return nullptr;
56425646
}
56435647

5648+
/// Retrieve the type of the default expression (if any) associated with
5649+
/// this parameter declaration.
5650+
Type getTypeOfDefaultExpr() const;
5651+
56445652
VarDecl *getStoredProperty() const {
56455653
if (auto stored = DefaultValueAndFlags.getPointer())
56465654
return stored->DefaultArg.dyn_cast<VarDecl *>();
@@ -5655,6 +5663,10 @@ class ParamDecl : public VarDecl {
56555663
/// parameter's fully type-checked default argument.
56565664
void setDefaultExpr(Expr *E, bool isTypeChecked);
56575665

5666+
/// Sets a type of default expression associated with this parameter.
5667+
/// This should only be called by deserialization.
5668+
void setDefaultExprType(Type type);
5669+
56585670
void setStoredProperty(VarDecl *var);
56595671

56605672
/// Retrieve the initializer context for the parameter's default argument.

include/swift/AST/DiagnosticsSema.def

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ NOTE(extended_type_declared_here,none,
3838
"extended type declared here", ())
3939
NOTE(opaque_return_type_declared_here,none,
4040
"opaque return type declared here", ())
41+
NOTE(default_value_declared_here,none,
42+
"default value declared here", ())
4143

4244
//------------------------------------------------------------------------------
4345
// MARK: Constraint solver diagnostics
@@ -6240,5 +6242,28 @@ ERROR(type_sequence_on_non_generic_param, none,
62406242
"'@_typeSequence' must appear on a generic parameter",
62416243
())
62426244

6245+
//------------------------------------------------------------------------------
6246+
// MARK: Type inference from default expressions
6247+
//------------------------------------------------------------------------------
6248+
6249+
ERROR(cannot_default_generic_parameter_inferrable_from_another_parameter, none,
6250+
"cannot use default expression for inference of %0 because it "
6251+
"is inferrable from parameters %1",
6252+
(Type, StringRef))
6253+
6254+
ERROR(cannot_default_generic_parameter_inferrable_through_same_type, none,
6255+
"cannot use default expression for inference of %0 because it "
6256+
"is inferrable through same-type requirement: '%1'",
6257+
(Type, StringRef))
6258+
6259+
ERROR(cannot_default_generic_parameter_invalid_requirement, none,
6260+
"cannot use default expression for inference of %0 because "
6261+
"requirement '%1' refers to other generic parameters",
6262+
(Type, StringRef))
6263+
6264+
ERROR(cannot_convert_default_value_type_to_argument_type, none,
6265+
"cannot convert default value of type %0 to expected argument type %1 for parameter #%2",
6266+
(Type, Type, unsigned))
6267+
62436268
#define UNDEFINE_DIAGNOSTIC_MACROS
62446269
#include "DefineDiagnosticMacros.h"

include/swift/AST/TypeCheckRequests.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class AccessorDecl;
4141
enum class AccessorKind;
4242
class ContextualPattern;
4343
class DefaultArgumentExpr;
44+
class DefaultArgumentType;
4445
class ClosureExpr;
4546
class GenericParamList;
4647
class PrecedenceGroupDecl;
@@ -2665,6 +2666,26 @@ class DefaultArgumentExprRequest
26652666
void cacheResult(Expr *expr) const;
26662667
};
26672668

2669+
/// Computes the type of the default expression for a given parameter.
2670+
class DefaultArgumentTypeRequest
2671+
: public SimpleRequest<DefaultArgumentTypeRequest, Type(ParamDecl *),
2672+
RequestFlags::SeparatelyCached> {
2673+
public:
2674+
using SimpleRequest::SimpleRequest;
2675+
2676+
private:
2677+
friend SimpleRequest;
2678+
2679+
// Evaluation.
2680+
Type evaluate(Evaluator &evaluator, ParamDecl *param) const;
2681+
2682+
public:
2683+
// Separate caching.
2684+
bool isCached() const { return true; }
2685+
Optional<Type> getCachedResult() const;
2686+
void cacheResult(Type type) const;
2687+
};
2688+
26682689
/// Computes the fully type-checked caller-side default argument within the
26692690
/// context of the call site that it will be inserted into.
26702691
class CallerSideDefaultArgExprRequest

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ SWIFT_REQUEST(TypeChecker, CustomAttrTypeRequest,
5959
SeparatelyCached, NoLocationInfo)
6060
SWIFT_REQUEST(TypeChecker, DefaultArgumentExprRequest,
6161
Expr *(ParamDecl *), SeparatelyCached, NoLocationInfo)
62+
SWIFT_REQUEST(TypeChecker, DefaultArgumentTypeRequest,
63+
Type(ParamDecl *), SeparatelyCached, NoLocationInfo)
6264
SWIFT_REQUEST(TypeChecker, DefaultArgumentInitContextRequest,
6365
Initializer *(ParamDecl *), SeparatelyCached, NoLocationInfo)
6466
SWIFT_REQUEST(TypeChecker, DefaultDefinitionTypeRequest,

include/swift/Basic/LangOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,10 @@ namespace swift {
718718
/// closures.
719719
bool EnableMultiStatementClosureInference = false;
720720

721+
/// Enable experimental support for generic parameter inference in
722+
/// parameter positions from associated default expressions.
723+
bool EnableTypeInferenceFromDefaultArguments = false;
724+
721725
/// See \ref FrontendOptions.PrintFullConvention
722726
bool PrintFullConvention = false;
723727
};

include/swift/Frontend/FrontendOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ class FrontendOptions {
447447
/// to encode the actual paths into the .swiftmodule file.
448448
PathObfuscator serializedPathObfuscator;
449449

450+
/// Avoid printing actual module content into the ABI descriptor file.
451+
/// This should only be used as a workaround when emitting ABI descriptor files
452+
/// crashes the compiler.
453+
bool emptyABIDescriptor = false;
454+
450455
private:
451456
static bool canActionEmitDependencies(ActionType);
452457
static bool canActionEmitReferenceDependencies(ActionType);

0 commit comments

Comments
 (0)