Skip to content

Commit 755f6aa

Browse files
committed
AST, SIL: Remove UTF16 encoding from StringLiteralExpr and StringLiteralInst
The UTF16 encoding is not used (anymore). I think it became obsolete with the switch to the UTF8 String representation.
1 parent 2b62570 commit 755f6aa

File tree

19 files changed

+5
-77
lines changed

19 files changed

+5
-77
lines changed

include/swift/AST/Expr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -861,9 +861,6 @@ class StringLiteralExpr : public LiteralExpr {
861861
/// A UTF-8 string.
862862
UTF8,
863863

864-
/// A UTF-16 string.
865-
UTF16,
866-
867864
/// A single UnicodeScalar, passed as an integer.
868865
OneUnicodeScalar
869866
};

include/swift/Basic/Unicode.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ bool isSingleUnicodeScalar(StringRef S);
6868

6969
unsigned extractFirstUnicodeScalar(StringRef S);
7070

71-
/// Get the length of the UTF8 string transcoded into UTF16.
72-
/// Returns the number of code units in UTF16 representation
73-
uint64_t getUTF16Length(StringRef Str);
74-
7571
} // end namespace unicode
7672
} // end namespace swift
7773

include/swift/SIL/SILInstruction.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3307,7 +3307,6 @@ class StringLiteralInst final
33073307
enum class Encoding {
33083308
Bytes,
33093309
UTF8,
3310-
UTF16,
33113310
/// UTF-8 encoding of an Objective-C selector.
33123311
ObjCSelector,
33133312
};

lib/AST/ASTDumper.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,6 @@ static StringRef
368368
getStringLiteralExprEncodingString(StringLiteralExpr::Encoding value) {
369369
switch (value) {
370370
case StringLiteralExpr::UTF8: return "utf8";
371-
case StringLiteralExpr::UTF16: return "utf16";
372371
case StringLiteralExpr::OneUnicodeScalar: return "unicodeScalar";
373372
}
374373

lib/Basic/Unicode.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,3 @@ unsigned swift::unicode::extractFirstUnicodeScalar(StringRef S) {
123123
(void)Result;
124124
return Scalar;
125125
}
126-
127-
uint64_t swift::unicode::getUTF16Length(StringRef Str) {
128-
uint64_t Length;
129-
// Transcode the string to UTF-16 to get its length.
130-
SmallVector<llvm::UTF16, 128> buffer(Str.size() + 1); // +1 for ending nulls.
131-
const llvm::UTF8 *fromPtr = (const llvm::UTF8 *) Str.data();
132-
llvm::UTF16 *toPtr = &buffer[0];
133-
llvm::ConversionResult Result =
134-
ConvertUTF8toUTF16(&fromPtr, fromPtr + Str.size(),
135-
&toPtr, toPtr + Str.size(),
136-
llvm::strictConversion);
137-
assert(Result == llvm::conversionOK &&
138-
"UTF-8 encoded string cannot be converted into UTF-16 encoding");
139-
(void)Result;
140-
141-
// The length of the transcoded string in UTF-16 code points.
142-
Length = toPtr - &buffer[0];
143-
return Length;
144-
}

lib/IRGen/GenConstant.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,6 @@ llvm::Constant *irgen::emitAddrOfConstantString(IRGenModule &IGM,
102102
case StringLiteralInst::Encoding::UTF8:
103103
return IGM.getAddrOfGlobalString(SLI->getValue());
104104

105-
case StringLiteralInst::Encoding::UTF16: {
106-
// This is always a GEP of a GlobalVariable with a nul terminator.
107-
auto addr = IGM.getAddrOfGlobalUTF16String(SLI->getValue());
108-
109-
// Cast to Builtin.RawPointer.
110-
return llvm::ConstantExpr::getBitCast(addr, IGM.Int8PtrTy);
111-
}
112-
113105
case StringLiteralInst::Encoding::ObjCSelector:
114106
llvm_unreachable("cannot get the address of an Objective-C selector");
115107
}

lib/SIL/IR/SILGlobalVariable.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ bool SILGlobalVariable::isValidStaticInitializerInst(const SILInstruction *I,
157157
switch (cast<StringLiteralInst>(I)->getEncoding()) {
158158
case StringLiteralInst::Encoding::Bytes:
159159
case StringLiteralInst::Encoding::UTF8:
160-
case StringLiteralInst::Encoding::UTF16:
161160
return true;
162161
case StringLiteralInst::Encoding::ObjCSelector:
163162
// Objective-C selector string literals cannot be used in static

lib/SIL/IR/SILInstructions.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,9 +1043,6 @@ CondFailInst *CondFailInst::create(SILDebugLocation DebugLoc, SILValue Operand,
10431043
}
10441044

10451045
uint64_t StringLiteralInst::getCodeUnitCount() {
1046-
auto E = unsigned(Encoding::UTF16);
1047-
if (SILInstruction::Bits.StringLiteralInst.TheEncoding == E)
1048-
return unicode::getUTF16Length(getValue());
10491046
return SILInstruction::Bits.StringLiteralInst.Length;
10501047
}
10511048

lib/SIL/IR/SILPrinter.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,6 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
13391339
switch (kind) {
13401340
case StringLiteralInst::Encoding::Bytes: return "bytes ";
13411341
case StringLiteralInst::Encoding::UTF8: return "utf8 ";
1342-
case StringLiteralInst::Encoding::UTF16: return "utf16 ";
13431342
case StringLiteralInst::Encoding::ObjCSelector: return "objc_selector ";
13441343
}
13451344
llvm_unreachable("bad string literal encoding");

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2619,8 +2619,6 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
26192619
StringLiteralInst::Encoding encoding;
26202620
if (P.Tok.getText() == "utf8") {
26212621
encoding = StringLiteralInst::Encoding::UTF8;
2622-
} else if (P.Tok.getText() == "utf16") {
2623-
encoding = StringLiteralInst::Encoding::UTF16;
26242622
} else if (P.Tok.getText() == "objc_selector") {
26252623
encoding = StringLiteralInst::Encoding::ObjCSelector;
26262624
} else if (P.Tok.getText() == "bytes") {

0 commit comments

Comments
 (0)