Skip to content

Commit

Permalink
Merge pull request #1059 from hylo-lang/emit-literal-cast
Browse files Browse the repository at this point in the history
Handle lvalue lowering for upcasts on numeric literals
  • Loading branch information
kyouko-taiga authored Oct 4, 2023
2 parents 12c55bf + bd4cb7a commit 8992ed1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/FrontEnd/TypeChecking/TypeChecker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3692,7 +3692,7 @@ struct TypeChecker {
_ = inferredType(of: program[e].left, updating: &obligations)

case .up:
// The type of thr LHS must be statically known to subtype of the RHS.
// The type of the LHS must be statically known to subtype of the RHS.
let lhs = inferredType(
of: program[e].left, withHint: ^freshVariable(), updating: &obligations)
obligations.insert(SubtypingConstraint(lhs, rhs.shape, origin: cause))
Expand Down
2 changes: 1 addition & 1 deletion Sources/IR/Analysis/Lifetime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ extension Module {
case (.closed(let lhs), .liveIn(let rhs)):
return .liveIn(lastUse: last(lhs, rhs))
case (.closed(let lhs), .closed(let rhs)):
return .liveIn(lastUse: last(lhs, rhs))
return .closed(lastUse: last(lhs, rhs))
}
}
return .init(operand: left.operand, coverage: coverage)
Expand Down
16 changes: 15 additions & 1 deletion Sources/IR/Emitter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2082,10 +2082,24 @@ struct Emitter {
/// Inserts the IR for lvalue `e`.
private mutating func emitLValue(_ e: CastExpr.ID) -> Operand {
switch ast[e].direction {
case .up:
return emitLValue(upcast: e)
case .pointerConversion:
return emitLValue(pointerConversion: e)
default:
UNIMPLEMENTED()
UNIMPLEMENTED("lvalue lowering for cast expressions #1049")
}
}

/// Inserts the IR for lvalue `e`.
private mutating func emitLValue(upcast e: CastExpr.ID) -> Operand {
switch ast[e].left.kind {
case FloatLiteralExpr.self:
return emitStore(value: ast[e].left)
case IntegerLiteralExpr.self:
return emitStore(value: ast[e].left)
default:
UNIMPLEMENTED("lvalue lowering for cast expressions #1049")
}
}

Expand Down
3 changes: 3 additions & 0 deletions Tests/HyloTests/TestCases/Lowering/NumericLiteral.hylo
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ public fun main() {

let _: Float32 = 1
let _: Float32 = 1.0

let _ = 1 as Int8
let _ = 1 as Float64
}

0 comments on commit 8992ed1

Please sign in to comment.