typed ag

29
Typed AG Alexey Rodriquez Y Faridah Liduan Type Systems Project 26 Jun 2003

Upload: elyse

Post on 05-Jan-2016

35 views

Category:

Documents


0 download

DESCRIPTION

Typed AG. Alexey Rodriquez Y Faridah Liduan Type Systems Project 26 Jun 2003. Introduction. Goals. Produce a well-typed AG file Detect type errors of semantic functions early in the AG stage Do type checking and type inferencing using: AG type annotations - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Typed AG

Typed AG

Alexey Rodriquez YFaridah Liduan

Type Systems Project26 Jun 2003

Page 2: Typed AG

Introduction

Page 3: Typed AG

Goals

Produce a well-typed AG fileDetect type errors of semantic functions early in the AG stageDo type checking and type inferencing using:

AG type annotationsTypes of haskell source fragmentLocal attributes definitions

Page 4: Typed AG

Why Typed AG?

Well typed AG => well typed haskell program Typed errors are given in terms of the AG source

Page 5: Typed AG

AG Type Errors in Terms of Haskell Source

Page 6: Typed AG

How to Merge AG and UHC

Page 7: Typed AG

Embedding AG to UHC (Attribute Haskell)

Advantages:Haskell is extended with attribute grammarMake use features of haskell interpreter and haskell compilerAG will have a module system if it is properly done

Disadvantages:Utterly Complex

Proper language design vs gluing

Page 8: Typed AG

Embedding UHC to AG (Typed AG)

Advantages:Easier to implement

Disadvantages:Still a two-step processImprovements in the UHC do not apply to Typed AG

Page 9: Typed AG

Our Choice

Implement Typed AG

Page 10: Typed AG

Typing Semantic Functions

Page 11: Typed AG

AG Data and Semantic Function Definition

Page 12: Typed AG

AG Generated Semantic Function

Page 13: Typed AG

How to Type Check Semantic Functions

Page 14: Typed AG

How to Type Check Semantic Functions (cont~)

Page 15: Typed AG

Simple Subset (no local attributes)

Page 16: Typed AG

Implementation of Typed AG

Page 17: Typed AG

AG Example

Page 18: Typed AG

AG Data Flow Diagram

Parse

input

Concretesyntax

HS blocks

Abstractsyntax

err_dos

sem_AG

sem_Grammar(copy rules)

err_trans

transformedAST

Gen.sem_Grammar(generate code)

HS ASTerr_gen

Generate HSHS source

file

ReportErrors Errors

Page 19: Typed AG

Implementation Choice

Parse

input

Concretesyntax

HS blocks

Abstractsyntax

err_dos

sem_AG

sem_Grammar(copy rules)

err_trans

transformedAST

Gen.sem_Grammar(generate code)

HS ASTerr_gen

Generate HSHS source

file

ReportErrors Errors

Parse

sem_UHC

Type inference

Environment+AG types

Type errors 1

Environment +haskell definitions

Type errors 2

Page 20: Typed AG

Other implementation choice?

Parse

input

Concretesyntax

HS blocks

Abstractsyntax

err_dos

sem_AG

sem_Grammar(copy rules)

err_trans

transformedAST

Gen.sem_Grammar(generate code)

HS ASTerr_gen

Generate HSHS source

file

ReportErrors Errors

Page 21: Typed AG

Type Inference of Local Attributes

Page 22: Typed AG

Implementation Options

Simple Dependency AnalysisType inference over local variables in the order determined by the analysis

Constraint: no cycles (cycle = incorrect result)

Use bindgroupPut all local attributes in a bindgroup and do type inferencing.

Disadvantages: no polymorphic local attributes

Page 23: Typed AG

Implementation Options (cont~)

Use HC ConstructorsUse semantic functions to type check local, synthesized, and inherited attributes.

Disadvantages:Error messages are not given in terms of original AG source.

Page 24: Typed AG

Implementation Issues

Page 25: Typed AG

AG + UHC

UHC copied to the AG repository.Slight modification of existing Makefiles.

Page 26: Typed AG

Current State of Affairs

Our implementation can detect type errors in the embedded Haskell source fragments.It can also detect type errors related to misuse of semantic functions.Type errors are also detected in the RHS of the attribute rules.

Page 27: Typed AG

Missing features from UHC and our implementation

Type synonyms are not supported.Types are not parsed.Omission of local attributes (& patterns).Typing of attribute expressions as a whole.

Page 28: Typed AG

Final Remarks

Typed AG guarantees well-typedness of generated Haskell source file.A really useful implementation of Typed AG will need modules and full Haskell.

Page 29: Typed AG

Q & A