Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eta573 #721

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ result
utils/scripts/lib/
release.log
binaries/
.gradle
.gradle
.idea
rts/.classpath
rts/.project
rts/.settings/
rts/rts.iml
13 changes: 7 additions & 6 deletions compiler/ETA/CodeGen/Closure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,21 @@ lfStandardForm args fvs

lfClass :: Bool -> Int -> Int -> LambdaFormInfo -> Text
lfClass hasStdLayout _arity fvs (LFThunk {..}) =
"eta/runtime/thunk/" <> thunkBase <> thunkExt
"eta/" <> thunkBase <> thunkExt
where thunkBase
| isTopLevel lfTopLevelFlag = "CAF"
| isTopLevel lfTopLevelFlag = "runtime/thunk/CAF"
| lfUpdatable = "UpdatableThunk"
| otherwise = "SingleEntryThunk"
| otherwise = "runtime/thunk/SingleEntryThunk"
thunkExt
| isTopLevel lfTopLevelFlag = mempty
| hasStdLayout = T.pack (show fvs)
| hasStdLayout = T.pack ((++) (show fvs) "runtime/thunk/")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rahulmutt I've tried | hasStdLayout = T.pack ((++) (show fvs) "runtime/thunk/") and | hasStdLayout = T.pack ((++) "runtime/thunk/" (show fvs) ) still I get Caused by: java.lang.ClassNotFoundException: eta.UpdatableThunk5runtime.thunk.error. Any idea?

Copy link
Member

@rahulmutt rahulmutt Apr 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you trying to add runtime/thunk/ instead of removing it above? Have you changed the names of all the eta/runtime/thunk/*Thunk* classes to eta/*Thunk*?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rahulmutt The classes Thunk, UpdatableThunk are only moved to package eta.
The remaining Thunk classes are present in package package eta/runtime/thunk.
when I make package as eta , I get getting CNFE for java.lang.NoClassDefFoundError: eta/UpdatableThunk2.
when I make package as eta/runtime/thunk/ , I get getting CNFE for java.lang.NoClassDefFoundError: eta/runtime/thunk/UpdatableThunk.
so, I'm trying to find way to include both eta/UpdatableThunk and eta/runtime/thunk/**.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will be easier if you shifted all the eta/runtime/thunk/** classes to eta/*. That way you won't have to add special cases in the logic.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rahulmutt - We could do that but I feel that makes rts code bit unorganized correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to move up the specialized thunks and functions up to the eta package. They will be exposed in the public runtime API for those who need it.

| otherwise = mempty

lfClass hasStdLayout args fvs (LFReEntrant {..})
= stgFun <> funExt
= "eta/runtime/apply/Function" <> funExt
where funExt
| hasStdLayout = T.pack (show args) <> fvsText
| args <= 6 = T.pack (show args)
| args <= 6 = T.pack ((show args))
| otherwise = mempty
fvsText
| fvs > 0 = "_" <> T.pack (show fvs)
Expand Down
8 changes: 4 additions & 4 deletions compiler/ETA/CodeGen/Layout.hs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ slowCall dflags loadContext fun argFtCodes
where n = length argFtCodes
ft = locFt fun
code = loadLoc fun
realCls = fromMaybe stgClosure $ locClass fun
realCls = fromMaybe etaClosure $ locClass fun
(arity, fts) = slowCallPattern $ map (\(a,_,_) -> a) argFtCodes
slowCode = directCall' loadContext True True realCls
(mkApFast arity realCls fts)
Expand All @@ -239,7 +239,7 @@ slowCall dflags loadContext fun argFtCodes
directCall :: Code -> Type -> CgLoc -> RepArity -> [(ArgRep, Maybe FieldType, Maybe Code)] -> (Code, Maybe Code)
directCall loadContext funType fun arity argFtCodes
| Just staticCode <- loadStaticMethod fun argFts
= directCall' loadContext True True stgClosure
= directCall' loadContext True True etaClosure
staticCode arity ((P, Nothing, Nothing):argFtCodes)
| arity' == arity =
directCall' loadContext True True realCls (mkApFast arity' realCls fts) arity'
Expand All @@ -249,7 +249,7 @@ directCall loadContext funType fun arity argFtCodes
code = loadLoc fun
ft = locFt fun
entryCode = enterMethod loadContext fun
realCls = fromMaybe stgClosure $ locClass fun
realCls = fromMaybe etaClosure $ locClass fun
argFts' = catMaybes . take arity $ map (\(_,ft,_) -> ft) argFtCodes
-- All this logic is to get around some weird issues with
-- the java monad type inlining. Ideally, argFts = staticFts
Expand Down Expand Up @@ -308,7 +308,7 @@ genApplyCall :: Code -> Int -> [FieldType] -> [(ArgRep, Maybe FieldType, Maybe C
genApplyCall loadContext arity fts args =
loadContext
<> fold loadCodes
<> mkApFast arity stgClosure fts
<> mkApFast arity etaClosure fts
where loadCodes = mapMaybe (\(_, _, a) -> a) args

getRepFtCodes :: [StgArg] -> CodeGen [(ArgRep, Maybe FieldType, Maybe Code)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/ETA/CodeGen/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ externaliseId _dflags id = do
cgTyCon :: TyCon -> CodeGen ()
cgTyCon tyCon = unless (null dataCons) $ do
dflags <- getDynFlags
(_, CgState {..}) <- newTypeClosure (tyConClass dflags tyCon) stgConstr
(_, CgState {..}) <- newTypeClosure (tyConClass dflags tyCon) etaDataCon
mapM_ (cgDataCon cgClassName) dataCons
when (isEnumerationTyCon tyCon) $
cgEnumerationTyCon cgClassName tyCon
Expand Down
33 changes: 18 additions & 15 deletions compiler/ETA/CodeGen/Rts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import qualified Data.Text as T
merge :: Text -> Text -> Text
merge x y = T.append x . T.cons '/' $ y

rts, apply, thunk, stg, exception, io, util, stm, par, interp, conc :: Text -> Text
rts, eta, etaex, apply, thunk, stg, exception, io, util, stm, par, interp, conc :: Text -> Text
rts = merge "eta/runtime"
eta = merge "eta"
etaex = merge "eta/exception"
apply = merge (rts "apply")
thunk = merge (rts "thunk")
stg = merge (rts "stg")
Expand All @@ -32,16 +34,16 @@ closureType, indStaticType, contextType, capabilityType, taskType, funType, tsoT
frameType, conType, thunkType, rtsConfigType, exitCodeType,
rtsOptsEnbledType, stgArrayType, stgByteArrayType, stgMutVarType, stgMVarType,
hsResultType, stgTVarType, stgBCOType, stgWeakType :: FieldType
closureType = obj stgClosure
closureType = obj etaClosure
indStaticType = obj stgIndStatic
contextType = obj stgContext
capabilityType = obj capability
taskType = obj task
funType = obj stgFun
funType = obj etaFun
tsoType = obj stgTSO
frameType = obj stackFrame
conType = obj stgConstr
thunkType = obj stgThunk
conType = obj etaDataCon
thunkType = obj etaThunk
rtsConfigType = obj rtsConfig
rtsOptsEnbledType = obj rtsOptsEnbled
exitCodeType = obj exitCode
Expand All @@ -54,19 +56,19 @@ hsResultType = obj hsResult
stgBCOType = obj stgBCO
stgWeakType = obj stgWeak

stgConstr, stgClosure, stgContext, capability, task, stgInd, stgIndStatic, stgThunk,
stgFun, stgTSO, stackFrame, rtsConfig, rtsOptsEnbled, exitCode, stgArray,
etaDataCon, etaClosure, stgContext, capability, task, stgInd, stgIndStatic, etaThunk,
etaFun, stgTSO, stackFrame, rtsConfig, rtsOptsEnbled, exitCode, stgArray,
stgByteArray, rtsUnsigned, stgMutVar, stgMVar, stgTVar, rtsGroup, hsResult,
stgBCO, stgWeak :: Text
stgConstr = stg "DataCon"
stgClosure = stg "Closure"
etaDataCon = eta "DataCon"
etaClosure = eta "Closure"
stgContext = stg "StgContext"
capability = stg "Capability"
capability = rts "Capability"
task = stg "Task"
stgInd = thunk "UpdatableThunk"
stgInd = eta "UpdatableThunk"
stgIndStatic = thunk "CAF"
stgThunk = thunk "Thunk"
stgFun = apply "Function"
etaThunk = eta "Thunk"
etaFun = eta "Function"
stgTSO = stg "TSO"
stackFrame = stg "StackFrame"
rtsConfig = rts "RtsConfig"
Expand Down Expand Up @@ -206,14 +208,15 @@ resumeInterruptsMethod :: Code
resumeInterruptsMethod =
invokevirtual $ mkMethodRef stgTSO "resumeInterrupts" [jbool] void

stgExceptionGroup, ioGroup, stmGroup, concGroup, parGroup, interpGroup, stgGroup :: Text
stgExceptionGroup, ioGroup, stmGroup, concGroup, parGroup, interpGroup, stgGroup, applyGroup :: Text
stgExceptionGroup = exception "Exception"
ioGroup = io "IO"
stmGroup = stm "STM"
concGroup = conc "Concurrent"
stgGroup = stg "Stg"
parGroup = par "Parallel"
interpGroup = interp "Interpreter"
applyGroup = apply "Apply"

-- Types
byteArrayBuf :: Code
Expand Down Expand Up @@ -275,7 +278,7 @@ getTagMethod :: Code -> Code
getTagMethod code
= code
<> gconv closureType conType
<> invokevirtual (mkMethodRef stgConstr "getTag" [] (ret jint))
<> invokevirtual (mkMethodRef etaDataCon "getTag" [] (ret jint))

printStream :: Text
printStream = "java/io/PrintStream"
Expand Down
4 changes: 2 additions & 2 deletions compiler/ETA/CodeGen/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,15 @@ enterMethod loadContext cgLoc
<> gconv closureType (obj closureCls)
<> loadContext
<> invokevirtual (mkMethodRef closureCls "enter" [contextType] (ret closureType))
where closureCls = fromMaybe stgClosure (locClass cgLoc)
where closureCls = fromMaybe etaClosure (locClass cgLoc)

evaluateMethod :: Code -> CgLoc -> Code
evaluateMethod loadContext cgLoc
= loadLoc cgLoc
<> gconv closureType (obj closureCls)
<> loadContext
<> invokevirtual (mkMethodRef closureCls "evaluate" [contextType] (ret closureType))
where closureCls = fromMaybe stgClosure (locClass cgLoc)
where closureCls = fromMaybe etaClosure (locClass cgLoc)

type RecIndexes = [(Int, Id)]
type RecInfo = (Text, Text, Text, FieldRef, Code, RecIndexes)
Expand Down
9 changes: 2 additions & 7 deletions libraries/base/java-utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@
import java.util.Set;
import java.util.List;
import java.util.HashSet;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

import java.nio.ByteOrder;
import java.nio.ByteBuffer;
import java.nio.file.Files;
Expand All @@ -35,20 +33,17 @@
import java.nio.channels.WritableByteChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import eta.runtime.Runtime;
import eta.runtime.RuntimeLogging;
import eta.runtime.stg.TSO;
import eta.runtime.stg.StgContext;
import eta.runtime.stg.Closure;
import eta.runtime.stg.Capability;
import eta.Closure;
import eta.runtime.Capability;
import eta.runtime.io.MemoryManager;

import ghc_prim.ghc.types.datacons.Czh;
import ghc_prim.ghc.types.datacons.ZC;
import ghc_prim.ghc.types.tycons.ZMZN;
import ghc_prim.ghc.Types;

import java.lang.management.ManagementFactory;
import com.sun.management.OperatingSystemMXBean;

Expand Down
1 change: 0 additions & 1 deletion libraries/ghc-prim/java/Utils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package eta.ghc_prim;

import java.nio.ByteBuffer;

import eta.runtime.io.MemoryManager;

public class Utils {
Expand Down
2 changes: 1 addition & 1 deletion libraries/integer/java/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.math.BigInteger;
import eta.runtime.stg.StgContext;
import eta.runtime.stg.Closure;
import eta.Closure;

public class Utils {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package eta.runtime.stg;
package eta;

import eta.runtime.stg.StgContext;
import java.io.Serializable;

import eta.runtime.stg.Capability;
import eta.runtime.stg.TSO;
import eta.runtime.thunk.Thunk;

import static eta.runtime.RuntimeLogging.barf;

public abstract class Closure implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package eta.runtime.stg;
package eta;

import eta.runtime.stg.Print;
import eta.runtime.stg.StgContext;

import static eta.runtime.RuntimeLogging.barf;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package eta.runtime.apply;
package eta;

import eta.runtime.apply.PAPSlow;
import eta.runtime.apply.PAP1_1;
import eta.runtime.stg.Print;
import eta.runtime.stg.Value;
import eta.runtime.stg.Closure;
import eta.runtime.stg.StgContext;
import eta.runtime.stg.ArgumentStack;

import static eta.runtime.RuntimeLogging.barf;

public abstract class Function extends Value {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
package eta.runtime.thunk;
package eta;

import java.lang.reflect.Field;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

import eta.runtime.stg.Print;
import eta.runtime.stg.Value;
import eta.runtime.stg.Capability;
import eta.runtime.stg.Closure;
import eta.runtime.Capability;
import eta.runtime.stg.StgContext;
import eta.runtime.stg.TSO;
import eta.runtime.thunk.*;
import eta.runtime.util.UnsafeUtil;
import eta.runtime.message.MessageBlackHole;
import eta.runtime.exception.Exception;
import eta.runtime.exception.EtaException;
import eta.exception.Exception;
import eta.exception.EtaException;
import eta.runtime.exception.EtaAsyncException;
import eta.runtime.exception.Raise;
import eta.runtime.exception.StgException;
import static eta.runtime.util.UnsafeUtil.UNSAFE;
import static eta.runtime.RuntimeLogging.barf;
import static eta.runtime.stg.TSO.WhyBlocked.*;

public abstract class Thunk extends Closure {
Expand Down Expand Up @@ -279,7 +275,7 @@ protected static boolean handleException(StgContext context, java.lang.Exception
if (raise == null) {
context.raise = raise = new Raise(((EtaException) thrw).exception);
}
ui.updatee.updateCode(context, raise);
ui.getUpdatee().updateCode(context, raise);
} //TODO: Handle EtaAsyncExceptions?
throw thrw;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eta.runtime.thunk;
package eta;

import eta.runtime.stg.Closure;
import eta.runtime.stg.StgContext;
import eta.runtime.thunk.UpdateInfo;

public abstract class UpdatableThunk extends Thunk {

Expand All @@ -28,7 +28,7 @@ public final Closure evaluate(StgContext context) {
context.popUpdate();
context.trampoline = trampoline;
}
if (ui.marked) {
if (ui.isMarked()) {
return updateCode(context, result);
} else {
updateWithIndirection(result);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package eta.runtime.stg;
package eta;

import eta.runtime.stg.StgContext;
import static eta.runtime.RuntimeLogging.barf;

public abstract class Value extends Closure {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eta.runtime.exception;
package eta.exception;

import eta.runtime.stg.Closure;
import eta.Closure;
import eta.runtime.exception.StgException;
import eta.runtime.stg.Closures;

public class EtaException extends StgException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package eta.runtime.exception;
package eta.exception;

import java.util.Arrays;
import java.util.ListIterator;

import eta.runtime.stg.Capability;
import eta.Closure;
import eta.runtime.exception.StgException;
import eta.runtime.exception.EtaAsyncException;
import eta.runtime.Capability;
import eta.runtime.stg.TSO;
import eta.runtime.stg.Closure;
import eta.runtime.stg.Closures;
import eta.runtime.stg.StgContext;
import eta.runtime.thunk.UpdateInfo;

import eta.runtime.Runtime;
import eta.runtime.message.MessageBlackHole;
import eta.runtime.message.MessageThrowTo;
Expand Down
Loading