Skip to content

Commit

Permalink
Merge pull request #5518 from swiftwasm/main
Browse files Browse the repository at this point in the history
[pull] swiftwasm from main
  • Loading branch information
kateinoigakukun committed Jun 14, 2023
2 parents 222c704 + 7143203 commit dd991b7
Show file tree
Hide file tree
Showing 146 changed files with 4,418 additions and 995 deletions.
4 changes: 4 additions & 0 deletions SwiftCompilerSources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ function(add_swift_compiler_modules_library name)
list(APPEND swift_compile_options "-O" "-cross-module-optimization")
endif()

if(NOT LLVM_ENABLE_ASSERTIONS)
list(APPEND swift_compile_options "-Xcc" "-DNDEBUG")
endif()

if(NOT SWIFT_STDLIB_SUPPORT_BACK_DEPLOYMENT)
list(APPEND swift_compile_options "-Xfrontend" "-disable-legacy-type-info")
endif()
Expand Down
62 changes: 61 additions & 1 deletion include/swift-c/DependencyScan/DependencyScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/// SWIFTSCAN_VERSION_MINOR should increase when there are API additions.
/// SWIFTSCAN_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
#define SWIFTSCAN_VERSION_MAJOR 0
#define SWIFTSCAN_VERSION_MINOR 3
#define SWIFTSCAN_VERSION_MINOR 4

SWIFTSCAN_BEGIN_DECLS

Expand Down Expand Up @@ -139,6 +139,10 @@ SWIFTSCAN_PUBLIC swiftscan_string_set_t *
swiftscan_swift_textual_detail_get_command_line(
swiftscan_module_details_t details);

SWIFTSCAN_PUBLIC swiftscan_string_set_t *
swiftscan_swift_textual_detail_get_bridging_pch_command_line(
swiftscan_module_details_t details);

SWIFTSCAN_PUBLIC swiftscan_string_set_t *
swiftscan_swift_textual_detail_get_extra_pcm_args(
swiftscan_module_details_t details);
Expand All @@ -154,6 +158,14 @@ SWIFTSCAN_PUBLIC swiftscan_string_set_t *
swiftscan_swift_textual_detail_get_swift_overlay_dependencies(
swiftscan_module_details_t details);

SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_swift_textual_detail_get_cas_fs_root_id(
swiftscan_module_details_t details);

SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_swift_textual_detail_get_module_cache_key(
swiftscan_module_details_t details);

//=== Swift Binary Module Details query APIs ------------------------------===//

SWIFTSCAN_PUBLIC swiftscan_string_ref_t
Expand All @@ -168,10 +180,18 @@ SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_swift_binary_detail_get_module_source_info_path(
swiftscan_module_details_t details);

SWIFTSCAN_PUBLIC swiftscan_string_set_t *
swiftscan_swift_binary_detail_get_header_dependencies(
swiftscan_module_details_t details);

SWIFTSCAN_PUBLIC bool
swiftscan_swift_binary_detail_get_is_framework(
swiftscan_module_details_t details);

SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_swift_binary_detail_get_module_cache_key(
swiftscan_module_details_t details);

//=== Swift Placeholder Module Details query APIs -------------------------===//

SWIFTSCAN_PUBLIC swiftscan_string_ref_t
Expand Down Expand Up @@ -200,6 +220,12 @@ swiftscan_clang_detail_get_command_line(swiftscan_module_details_t details);
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
swiftscan_clang_detail_get_captured_pcm_args(swiftscan_module_details_t details);

SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_clang_detail_get_cas_fs_root_id(swiftscan_module_details_t details);

SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_clang_detail_get_module_cache_key(swiftscan_module_details_t details);

//=== Batch Scan Input Functions ------------------------------------------===//

/// Create an \c swiftscan_batch_scan_input_t instance.
Expand Down Expand Up @@ -402,6 +428,40 @@ swiftscan_scanner_cache_reset(swiftscan_scanner_t scanner);
/// An entry point to invoke the compiler via a library call.
SWIFTSCAN_PUBLIC int invoke_swift_compiler(int argc, const char **argv);

//=== Scanner CAS Operations ----------------------------------------------===//

/// Opaque container for a CAS instance that includes both ObjectStore and
/// ActionCache.
typedef struct swiftscan_cas_s *swiftscan_cas_t;

/// Enum types for output types for cache key computation.
/// TODO: complete the list.
typedef enum {
SWIFTSCAN_OUTPUT_TYPE_OBJECT = 0,
SWIFTSCAN_OUTPUT_TYPE_SWIFTMODULE = 1,
SWIFTSCAN_OUTPUT_TYPE_SWIFTINTERFACE = 2,
SWIFTSCAN_OUTPUT_TYPE_SWIFTPRIAVEINTERFACE = 3,
SWIFTSCAN_OUTPUT_TYPE_CLANG_MODULE = 4,
SWIFTSCAN_OUTPUT_TYPE_CLANG_PCH = 5
} swiftscan_output_kind_t;

/// Create a \c cas instance that points to path.
SWIFTSCAN_PUBLIC swiftscan_cas_t swiftscan_cas_create(const char *path);

/// Dispose the \c cas instance.
SWIFTSCAN_PUBLIC void swiftscan_cas_dispose(swiftscan_cas_t cas);

/// Store content into CAS. Return \c CASID as string.
SWIFTSCAN_PUBLIC swiftscan_string_ref_t swiftscan_cas_store(swiftscan_cas_t cas,
uint8_t *data,
unsigned size);

/// Compute \c CacheKey for output of \c kind from the compiler invocation \c
/// argc and \c argv with \c input. Return \c CacheKey as string.
SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_compute_cache_key(swiftscan_cas_t cas, int argc, const char **argv,
const char *input, swiftscan_output_kind_t kind);

//===----------------------------------------------------------------------===//

SWIFTSCAN_END_DECLS
Expand Down
43 changes: 26 additions & 17 deletions include/swift/AST/ASTScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
return nullptr;
}

virtual NullablePtr<MacroExpansionDecl> getFreestandingMacro() const {
return nullptr;
}

#pragma mark - debugging and printing

public:
Expand Down Expand Up @@ -278,6 +282,10 @@ class ASTScopeImpl : public ASTAllocated<ASTScopeImpl> {
static std::pair<CaseStmt *, CaseStmt *>
lookupFallthroughSourceAndDest(SourceFile *sourceFile, SourceLoc loc);

static void lookupEnclosingMacroScope(
SourceFile *sourceFile, SourceLoc loc,
llvm::function_ref<bool(ASTScope::PotentialMacro)> consume);

/// Scopes that cannot bind variables may set this to true to create more
/// compact scope tree in the debug info.
virtual bool ignoreInDebugInfo() const { return false; }
Expand Down Expand Up @@ -840,24 +848,20 @@ class DefaultArgumentInitializerScope final : public ASTScopeImpl {
bool ignoreInDebugInfo() const override { return true; }
};

/// Consider:
/// @_propertyWrapper
/// struct WrapperWithInitialValue {
/// }
/// struct HasWrapper {
/// @WrapperWithInitialValue var y = 17
/// }
/// Lookup has to be able to find the use of WrapperWithInitialValue, that's
/// what this scope is for. Because the source positions are screwy.

class AttachedPropertyWrapperScope final : public ASTScopeImpl {
/// The scope for custom attributes and their arguments, such as for
/// attached property wrappers and for attached macros.
///
/// Source locations for the attribute name and its arguments are in the
/// custom attribute, so lookup is invoked from within the attribute
/// itself.
class CustomAttributeScope final : public ASTScopeImpl {
public:
CustomAttr *attr;
VarDecl *decl;
Decl *decl;

AttachedPropertyWrapperScope(CustomAttr *attr, VarDecl *decl)
CustomAttributeScope(CustomAttr *attr,Decl *decl)
: attr(attr), decl(decl) {}
virtual ~AttachedPropertyWrapperScope() {}
virtual ~CustomAttributeScope() {}

protected:
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;
Expand All @@ -871,7 +875,8 @@ class AttachedPropertyWrapperScope final : public ASTScopeImpl {
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
return attr;
}
bool ignoreInDebugInfo() const override { return true; }
bool ignoreInDebugInfo() const override { return true; }

private:
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);
};
Expand Down Expand Up @@ -1134,9 +1139,9 @@ class SpecializeAttributeScope final : public ASTScopeImpl {
class DifferentiableAttributeScope final : public ASTScopeImpl {
public:
DifferentiableAttr *const differentiableAttr;
ValueDecl *const attributedDeclaration;
Decl *const attributedDeclaration;

DifferentiableAttributeScope(DifferentiableAttr *diffAttr, ValueDecl *decl)
DifferentiableAttributeScope(DifferentiableAttr *diffAttr, Decl *decl)
: differentiableAttr(diffAttr), attributedDeclaration(decl) {}
virtual ~DifferentiableAttributeScope() {}

Expand Down Expand Up @@ -1270,6 +1275,10 @@ class MacroExpansionDeclScope final : public ASTScopeImpl {
SourceRange
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;

NullablePtr<MacroExpansionDecl> getFreestandingMacro() const override {
return decl;
}

protected:
void printSpecifics(llvm::raw_ostream &out) const override;

Expand Down
5 changes: 3 additions & 2 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3902,7 +3902,7 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
/// protocols to which the nominal type conforms. Furthermore, the resulting
/// set of declarations has not been filtered for visibility, nor have
/// overridden declarations been removed.
TinyPtrVector<ValueDecl *> lookupDirect(DeclName name,
TinyPtrVector<ValueDecl *> lookupDirect(DeclName name, SourceLoc loc = SourceLoc(),
OptionSet<LookupDirectFlags> flags =
OptionSet<LookupDirectFlags>());

Expand Down Expand Up @@ -4457,7 +4457,8 @@ class ClassDecl final : public NominalTypeDecl {
// Force loading all the members, which will add this attribute if any of
// members are determined to be missing while loading.
auto mutableThis = const_cast<ClassDecl *>(this);
(void)mutableThis->lookupDirect(DeclBaseName::createConstructor());
(void)mutableThis->lookupDirect(DeclBaseName::createConstructor(),
getStartLoc());
}

if (Bits.ClassDecl.ComputedHasMissingDesignatedInitializers)
Expand Down
7 changes: 4 additions & 3 deletions include/swift/AST/DeclContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ class alignas(1 << DeclContextAlignInBits) DeclContext
/// lookup.
///
/// \returns true if anything was found.
bool lookupQualified(Type type, DeclNameRef member, NLOptions options,
bool lookupQualified(Type type, DeclNameRef member,
SourceLoc loc, NLOptions options,
SmallVectorImpl<ValueDecl *> &decls) const;

/// Look for the set of declarations with the given name within the
Expand All @@ -616,12 +617,12 @@ class alignas(1 << DeclContextAlignInBits) DeclContext
///
/// \returns true if anything was found.
bool lookupQualified(ArrayRef<NominalTypeDecl *> types, DeclNameRef member,
NLOptions options,
SourceLoc loc, NLOptions options,
SmallVectorImpl<ValueDecl *> &decls) const;

/// Perform qualified lookup for the given member in the given module.
bool lookupQualified(ModuleDecl *module, DeclNameRef member,
NLOptions options,
SourceLoc loc, NLOptions options,
SmallVectorImpl<ValueDecl *> &decls) const;

/// Look up all Objective-C methods with the given selector visible
Expand Down
7 changes: 4 additions & 3 deletions include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -766,9 +766,10 @@ ERROR(sil_movechecking_borrowed_parameter_captured_by_closure, none,
"parameter",
(StringRef))
ERROR(sil_movechecking_capture_consumed, none,
"noncopyable '%0' cannot be consumed when captured by a closure", (StringRef))
ERROR(sil_movechecking_inout_not_reinitialized_before_end_of_function, none,
"missing reinitialization of inout parameter '%0' after consume", (StringRef))
"noncopyable '%0' cannot be consumed when captured by an escaping closure", (StringRef))
ERROR(sil_movechecking_not_reinitialized_before_end_of_function, none,
"missing reinitialization of %select{inout parameter|closure capture}1 '%0' "
"after consume", (StringRef, bool))
ERROR(sil_movechecking_value_consumed_in_a_loop, none,
"'%0' consumed in a loop", (StringRef))
ERROR(sil_movechecking_use_after_partial_consume, none,
Expand Down
4 changes: 4 additions & 0 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -7194,6 +7194,10 @@ ERROR(macro_accessor_missing_from_expansion,none,
ERROR(macro_init_accessor_not_documented,none,
"expansion of macro %0 produced an unexpected 'init' accessor",
(DeclName))
ERROR(global_arbitrary_name,none,
"'%0' macros are not allowed to introduce arbitrary names "
"at global scope",
(StringRef))

ERROR(macro_resolve_circular_reference, none,
"circular reference resolving %select{freestanding|attached}0 macro %1",
Expand Down
22 changes: 0 additions & 22 deletions include/swift/AST/Evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,6 @@ class Evaluator {
/// is treated as a stack and is used to detect cycles.
llvm::SetVector<ActiveRequest> activeRequests;

/// How many `ResolveMacroRequest` requests are active.
///
/// This allows us to quickly determine whether there is any
/// `ResolveMacroRequest` active in the active request stack.
/// It saves us from a linear scan through `activeRequests` when
/// we need to determine this information.
///
/// Why on earth would we need to determine this information?
/// Please see the extended comment that goes with the constructor
/// of `UnqualifiedLookupRequest`.
unsigned numActiveResolveMacroRequests = 0;

/// A cache that stores the results of requests.
evaluator::RequestCache cache;

Expand Down Expand Up @@ -342,16 +330,6 @@ class Evaluator {
return activeRequests.count(ActiveRequest(request));
}

/// Determine whether there is any active "resolve macro" request
/// on the request stack.
///
/// Why on earth would we need to determine this information?
/// Please see the extended comment that goes with the constructor
/// of `UnqualifiedLookupRequest`.
bool hasActiveResolveMacroRequest() const {
return numActiveResolveMacroRequests > 0;
}

private:
/// Diagnose a cycle detected in the evaluation of the given
/// request.
Expand Down

0 comments on commit dd991b7

Please sign in to comment.