Skip to content

Commit c25fe60

Browse files
aykevldeadprogram
authored andcommitted
compiler: do not return an error from getLLVMType
This commit replaces "unknown type" errors in getLLVMType with panics. The main reason this is done is that it simplifies the code *a lot*. Many `if err != nil` lines were there just because of type information. Additionally, simply panicking is probably a better approach as the only way this error can be produced is either with big new language features or a serious compiler bug. Panicking is probably a better way to handle this error anyway.
1 parent 6d23809 commit c25fe60

File tree

6 files changed

+101
-293
lines changed

6 files changed

+101
-293
lines changed

compiler/channel.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ import (
1212

1313
// emitMakeChan returns a new channel value for the given channel type.
1414
func (c *Compiler) emitMakeChan(expr *ssa.MakeChan) (llvm.Value, error) {
15-
valueType, err := c.getLLVMType(expr.Type().(*types.Chan).Elem())
16-
if err != nil {
17-
return llvm.Value{}, err
18-
}
15+
valueType := c.getLLVMType(expr.Type().(*types.Chan).Elem())
1916
if c.targetData.TypeAllocSize(valueType) > c.targetData.TypeAllocSize(c.intType) {
2017
// Values bigger than int overflow the data part of the coroutine.
2118
// TODO: make the coroutine data part big enough to hold these bigger
@@ -33,10 +30,7 @@ func (c *Compiler) emitMakeChan(expr *ssa.MakeChan) (llvm.Value, error) {
3330
// emitChanSend emits a pseudo chan send operation. It is lowered to the actual
3431
// channel send operation during goroutine lowering.
3532
func (c *Compiler) emitChanSend(frame *Frame, instr *ssa.Send) error {
36-
valueType, err := c.getLLVMType(instr.Chan.Type().(*types.Chan).Elem())
37-
if err != nil {
38-
return err
39-
}
33+
valueType := c.getLLVMType(instr.Chan.Type().(*types.Chan).Elem())
4034
ch, err := c.parseExpr(frame, instr.Chan)
4135
if err != nil {
4236
return err
@@ -56,10 +50,7 @@ func (c *Compiler) emitChanSend(frame *Frame, instr *ssa.Send) error {
5650
// emitChanRecv emits a pseudo chan receive operation. It is lowered to the
5751
// actual channel receive operation during goroutine lowering.
5852
func (c *Compiler) emitChanRecv(frame *Frame, unop *ssa.UnOp) (llvm.Value, error) {
59-
valueType, err := c.getLLVMType(unop.X.Type().(*types.Chan).Elem())
60-
if err != nil {
61-
return llvm.Value{}, err
62-
}
53+
valueType := c.getLLVMType(unop.X.Type().(*types.Chan).Elem())
6354
valueSize := llvm.ConstInt(c.uintptrType, c.targetData.TypeAllocSize(valueType), false)
6455
ch, err := c.parseExpr(frame, unop.X)
6556
if err != nil {
@@ -83,11 +74,8 @@ func (c *Compiler) emitChanRecv(frame *Frame, unop *ssa.UnOp) (llvm.Value, error
8374

8475
// emitChanClose closes the given channel.
8576
func (c *Compiler) emitChanClose(frame *Frame, param ssa.Value) error {
86-
valueType, err := c.getLLVMType(param.Type().(*types.Chan).Elem())
77+
valueType := c.getLLVMType(param.Type().(*types.Chan).Elem())
8778
valueSize := llvm.ConstInt(c.uintptrType, c.targetData.TypeAllocSize(valueType), false)
88-
if err != nil {
89-
return err
90-
}
9179
ch, err := c.parseExpr(frame, param)
9280
if err != nil {
9381
return err

0 commit comments

Comments
 (0)