@Ben_Cohen, I must be dim but I’m having trouble mapping what you suggest onto my understanding of how these protocols work. _ExpressibleByBuiltinUnicodeScalarLiteral is a constraint on the associated type UnicodeScalarLiteralType
public protocol ExpressibleByUnicodeScalarLiteral {
/// A type that represents a Unicode scalar literal.
///
/// Valid types for `UnicodeScalarLiteralType` are `Unicode.Scalar`,
/// `Character`, `String`, and `StaticString`.
associatedtype UnicodeScalarLiteralType : _ExpressibleByBuiltinUnicodeScalarLiteral
/// Creates an instance initialized to the given value.
///
/// - Parameter value: The value of the new instance.
init(unicodeScalarLiteral value: UnicodeScalarLiteralType)
}
so it is not possible to use ExpressibleByUnicodeScalarLiteral on a type without a conformance to _ExpressibleByBuiltinUnicodeScalarLiteral and I know of no other way to initialise an int-like type from a character/string literal. I also can’t see this affects whether values can be compile time checked as it all happens in CSAppy.cpp when the destination type looks like an Int.
I’d like to take another tack however. The implementation of these conformances are never used at run time. I don’t know how, but if you look at the assembly language for when a character literal is used the ASCII value has been transformed all the way to an Integer constant in a single instruction e.g. cmp.
let i: Int8 = 99
if i == 'a' {
}
bin/swiftc -target armv7-apple-ios10.3 -S i.swift -o ~/a.s
gives:
.section __TEXT,__text,regular,pure_instructions
.ios_version_min 10, 3
.syntax unified
.globl _main
.p2align 1
.code 16
.thumb_func _main
_main:
sub sp, #8
movs r2, #99
movw r3, :lower16:(_$s1a1is4Int8Vvp-(LPC0_0+4))
movt r3, :upper16:(_$s1a1is4Int8Vvp-(LPC0_0+4))
LPC0_0:
add r3, pc
strb r2, [r3]
ldrsb.w r2, [r3]
cmp r2, #97
str r0, [sp, #4]
str r1, [sp]
bne LBB0_2
b LBB0_3
LBB0_2:
b LBB0_3
LBB0_3:
movs r0, #0
add sp, #8
bx lr
There is no reference or linkage to the witness tables or symbols of the standard library so this is not an ABI issue at all. Where it me I’d go to review as originally proposed with both conformances as the use of these integer conformances and implementations never make it past the compiler in a way that would affect a program as far as I can see.