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

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

    19-Dec-2015
  • Category

    Documents

  • view

    218
  • download

    1

Transcript of Typed AG Alexey Rodriquez Y Faridah Liduan Type Systems Project 26 Jun 2003.

Typed AG

Alexey Rodriquez YFaridah Liduan

Type Systems Project26 Jun 2003

Introduction

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

Why Typed AG?

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

AG Type Errors in Terms of Haskell Source

How to Merge AG and UHC

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

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

Our Choice

Implement Typed AG

Typing Semantic Functions

AG Data and Semantic Function Definition

AG Generated Semantic Function

How to Type Check Semantic Functions

How to Type Check Semantic Functions (cont~)

Simple Subset (no local attributes)

Implementation of Typed AG

AG Example

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

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

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

Type Inference of Local Attributes

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

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.

Implementation Issues

AG + UHC

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

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.

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.

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.

Q & A