aboutsummaryrefslogtreecommitdiffhomepage
path: root/compiler/channel.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-04-21 14:34:37 +0200
committerRon Evans <[email protected]>2019-04-26 08:52:10 +0200
commitc25fe609a9d1431e43c39fa8f0816b83ee6e7f1e (patch)
treeeea8e51a051e24346c7cc0270064d422b2060406 /compiler/channel.go
parent6d2380921818fdbbdbca0db6c1ef732654792d58 (diff)
downloadtinygo-c25fe609a9d1431e43c39fa8f0816b83ee6e7f1e.tar.gz
tinygo-c25fe609a9d1431e43c39fa8f0816b83ee6e7f1e.zip
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.
Diffstat (limited to 'compiler/channel.go')
-rw-r--r--compiler/channel.go20
1 files changed, 4 insertions, 16 deletions
diff --git a/compiler/channel.go b/compiler/channel.go
index 05973ecbf..4a18f0647 100644
--- a/compiler/channel.go
+++ b/compiler/channel.go
@@ -12,10 +12,7 @@ import (
// emitMakeChan returns a new channel value for the given channel type.
func (c *Compiler) emitMakeChan(expr *ssa.MakeChan) (llvm.Value, error) {
- valueType, err := c.getLLVMType(expr.Type().(*types.Chan).Elem())
- if err != nil {
- return llvm.Value{}, err
- }
+ valueType := c.getLLVMType(expr.Type().(*types.Chan).Elem())
if c.targetData.TypeAllocSize(valueType) > c.targetData.TypeAllocSize(c.intType) {
// Values bigger than int overflow the data part of the coroutine.
// 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) {
// emitChanSend emits a pseudo chan send operation. It is lowered to the actual
// channel send operation during goroutine lowering.
func (c *Compiler) emitChanSend(frame *Frame, instr *ssa.Send) error {
- valueType, err := c.getLLVMType(instr.Chan.Type().(*types.Chan).Elem())
- if err != nil {
- return err
- }
+ valueType := c.getLLVMType(instr.Chan.Type().(*types.Chan).Elem())
ch, err := c.parseExpr(frame, instr.Chan)
if err != nil {
return err
@@ -56,10 +50,7 @@ func (c *Compiler) emitChanSend(frame *Frame, instr *ssa.Send) error {
// emitChanRecv emits a pseudo chan receive operation. It is lowered to the
// actual channel receive operation during goroutine lowering.
func (c *Compiler) emitChanRecv(frame *Frame, unop *ssa.UnOp) (llvm.Value, error) {
- valueType, err := c.getLLVMType(unop.X.Type().(*types.Chan).Elem())
- if err != nil {
- return llvm.Value{}, err
- }
+ valueType := c.getLLVMType(unop.X.Type().(*types.Chan).Elem())
valueSize := llvm.ConstInt(c.uintptrType, c.targetData.TypeAllocSize(valueType), false)
ch, err := c.parseExpr(frame, unop.X)
if err != nil {
@@ -83,11 +74,8 @@ func (c *Compiler) emitChanRecv(frame *Frame, unop *ssa.UnOp) (llvm.Value, error
// emitChanClose closes the given channel.
func (c *Compiler) emitChanClose(frame *Frame, param ssa.Value) error {
- valueType, err := c.getLLVMType(param.Type().(*types.Chan).Elem())
+ valueType := c.getLLVMType(param.Type().(*types.Chan).Elem())
valueSize := llvm.ConstInt(c.uintptrType, c.targetData.TypeAllocSize(valueType), false)
- if err != nil {
- return err
- }
ch, err := c.parseExpr(frame, param)
if err != nil {
return err