Skip to content

[DNM] Revert #80925 and #80749 to check if they are the cause of source compatibility regressions #80932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
65 changes: 7 additions & 58 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4583,70 +4583,19 @@ namespace {
if (dc->isTypeContext())
isStatic = true;

// For now we don't import static constexpr. TODO: Lift this restriction.
// For now we don't import static constexpr
if (isStatic && decl->isConstexpr())
return nullptr;

auto introducer = Impl.shouldImportGlobalAsLet(decl->getType())
? VarDecl::Introducer::Let
: VarDecl::Introducer::Var;

ValueDecl *result = nullptr;

bool initIsEvaluatable = false;
if (auto init = decl->getInit()) {
// Don't import values for partial specializations. TODO: Should we stop
// importing partially specialized variables completely?
bool partial = isa<clang::VarTemplatePartialSpecializationDecl>(decl);

// Don't import values when type-dependent or value-dependent.
bool typeDependent = decl->getType()->isDependentType();
bool valueDependent = init->isValueDependent();

initIsEvaluatable = !partial && !typeDependent && !valueDependent;
}

// If the variable is const (we're importing it as a let), and has an
// initializer, then ask Clang for its constant value and synthesize a
// getter with that value.
if (introducer == VarDecl::Introducer::Let && initIsEvaluatable) {
auto val = decl->evaluateValue();
// For now, only import integer and float constants. If in the future
// SwiftDeclSynthesizer::createConstant becomes able to import more
// types, we can lift this restriction.
if (val && (val->isFloat() || val->isInt())) {
auto type = Impl.importTypeIgnoreIUO(
decl->getType(), ImportTypeKind::Value,
ImportDiagnosticAdder(Impl, decl, decl->getLocation()),
isInSystemModule(dc), Bridgeability::None, ImportTypeAttrs());

// FIXME: Handle CGFloat too.
if (type && !type->isCGFloat()) {
auto convertKind = ConstantConvertKind::None;
// Request conversions on enums, and swift_wrapper((enum/struct))
// types
if (decl->getType()->isEnumeralType())
convertKind = ConstantConvertKind::Construction;
else if (findSwiftNewtype(decl, Impl.getClangSema(),
Impl.CurrentVersion))
convertKind = ConstantConvertKind::Construction;

result = synthesizer.createConstant(
name, dc, type, *val, convertKind, isStatic, decl,
importer::convertClangAccess(decl->getAccess()));
}
}
}

// Otherwise, import as an external declaration
if (!result) {
result = Impl.createDeclWithClangNode<VarDecl>(
decl, importer::convertClangAccess(decl->getAccess()),
/*IsStatic*/ isStatic, introducer,
Impl.importSourceLoc(decl->getLocation()), name, dc);
result->setIsObjC(false);
result->setIsDynamic(false);
}
auto result = Impl.createDeclWithClangNode<VarDecl>(
decl, importer::convertClangAccess(decl->getAccess()),
/*IsStatic*/ isStatic, introducer,
Impl.importSourceLoc(decl->getLocation()), name, dc);
result->setIsObjC(false);
result->setIsDynamic(false);

// If imported as member, the member should be final.
if (dc->getSelfClassDecl())
Expand Down
174 changes: 0 additions & 174 deletions test/ClangImporter/const_values.swift

This file was deleted.

103 changes: 0 additions & 103 deletions test/ClangImporter/const_values_cxx.swift

This file was deleted.

19 changes: 0 additions & 19 deletions test/ClangImporter/const_values_fail.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// CHECK: public init()
// CHECK: private init()
// CHECK: public func privateRecMethod()
// CHECK: public static var PRIVATE_REC_CONST: Bool { get }
// CHECK: public static let PRIVATE_REC_CONST: Bool
// CHECK: }

// CHECK: private struct PrivateEnum : Hashable, Equatable, RawRepresentable {
Expand All @@ -26,7 +26,7 @@
// CHECK: case privateEnumClassMember
// CHECK: }

// CHECK: private static var PRIVATE_CONST: Bool { get }
// CHECK: private static let PRIVATE_CONST: Bool

// CHECK: private static var privateAliasVal: Leaky.PrivateAlias
// CHECK: private static var privateRecVal: Leaky.PrivateRec
Expand Down
Loading